import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    int n = scan!int;
    int[] as = scan.map!(c => c.to!int - '1').array;

    bool has1 = 0;
    foreach(a; as) if(a == 1) has1 = 1;
    log("as:", as, "has1:", has1);

    if(! has1) foreach(i; 0 .. n) as[i] /= 2;
    log("as:", as);

    while(n > 1){
        int m = maxm(n);
        as = f(as, n, m);
        n = as.length.to!int;
        log("n:", n, "as:", as);
    }

    int ans = as[0];
    if(! has1) ans *= 2;

    if(has1 && ans == 2) "0".writeln;
    else ans.writeln;
    
}
int maxm(int n){
    int m = 1;
    while(m * 2 < n) m *= 2;
    return m;
}


int[] f(int[] as, int n, int m){ // m = 2 ** k
    int[] res;
    foreach(i; 0 .. n - m) res ~= abs(as[i] - as[i + m]);
    return res;
}