using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication289
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str1 = Console.ReadLine().Split();
            int n = int.Parse(str1[0]);
            int m = int.Parse(str1[1]);
            long[,] mat = new long[n, m];
            long suma = 0;
            for(int i = 0; i<n;i++)
            {
                string[] str2 = Console.ReadLine().Split();
                for(int j = 0; j<m;j++)
                {
                    mat[i, j] = long.Parse(str2[j]);
                    suma+=mat[i, j];
                }
            }
            Array.Sort(mat);
            if(n==1)
            {
                long[,] b = new long[0,m];
                long s = 0;
                for(long i = 1; i<=mat[0, m-1]; i*=2)
                {
                    for(int j = 0; j<m-1;j++)
                    {
                        b[0,j] = i ^ mat[0, j];
                        s += b[0,j];
                    }
                    if(s<suma)
                    {
                        mat = b;
                        suma = s;
                    }
                }
            }
            Console.WriteLine(suma);
        }
    }
}