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

namespace ConsoleApp3
{
    internal class Program
    {
        static void pisi(long n, long[] niz)
        {
            long i = 0;
            for (i = 0; i < n; i++)
            {
                Console.Write(niz[i]);
                Console.Write(' ');
            }
            Console.WriteLine();
        }
        static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long m = long.Parse(s[1]);
            long[] niz = new long[m];
            long i, j, min = 0;
            bool nije_gotovo = true;
            long suma1 = 0, suma = 0;
            s = Console.ReadLine().Split(' ');
            for(i=0; i<m; i++)
            {
                niz[i] = long.Parse(s[i]);
                suma1 += niz[i];
            }
            while (nije_gotovo)
            {
                Array.Sort(niz);
                pisi(m, niz);
                min = niz[0];
                for (i = 0; i < m; i++)
                {
                    suma += niz[i] ^ min;
                    niz[i] = niz[i] ^ min;
                }
                
                if (suma >= suma1)
                {
                    nije_gotovo = false;
                }
                if (nije_gotovo)
                {
                    suma1 = suma;
                }
            }
            Console.WriteLine(suma1);
        }
    }
}