#include <cstdio>
#include <iostream>
#include<utility>
#define MAXN 500005
using namespace std;
unsigned long long int a[MAXN];
unsigned long long int d[MAXN];
int n;
pair <unsigned long long int , unsigned long long int >  resi(int t,int p)
{
    int i,j,k;
    unsigned long long int g,h;
    pair <unsigned long long int , unsigned long long int > f;
    if (p==n-1)
    {
        return make_pair(a[n-1]+t,a[n-1]+t);
    }
    for (i=t;i>=0;i--)
    {
        g=a[p]+i;
        f=resi(t-i,p+1);
        return make_pair(g&f.first,g^f.second);
    }
}
int main()
{
    int i,j,k;
    unsigned long long int c;
    pair <unsigned long long int , unsigned long long int > b;
    scanf("%d",&n);
    for (i=0;i<n;i++) scanf("%llu",&a[i]),d[i]=a[i];
   /* unsigned long long*/ int t=0;
    while (true)
    {
       b= resi(t,0);
       if (b.first!=0 && b.second!=0) break;
       t++;
    }
    printf("%d",t);
    return 0;
}