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]);
            if (n == 1)
            {
                long[] mat = new long[m];
                long suma = 0;
                string[] str2 = Console.ReadLine().Split();
                for (int j = 0; j < m; j++)
                {
                    mat[j] = long.Parse(str2[j]);
                    suma += mat[j];
                }
                Array.Sort(mat);
                long[] b = new long[m];
                long s = 0;
                for (long i = 1; i <= mat[m - 1]; i *= 2)
                {
                    for (int j = 0; j < m - 1; j++)
                    {
                        b[j] = i ^ mat[j];
                        s += b[j];
                    }
                    if (s < suma)
                    {
                        mat = b;
                        suma = s;
                    }
                }
                Console.WriteLine(suma);
            }
        }
    }
}