d[99999],a[20],i='€',j,k,n;main(m){for(gets(a);~scanf("%d",a+j++););for(;i--;)for(j=16;j--;m=fmax(0,a[j]-m),d[k=i^1<>k&1)*a[k];i=!printf("%d",*d);}