#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

int n,m;


int solveBrute(istream& cin, ostream& cout) {
	cin >> n;
	string seq;
	cin >> seq;
	vector<set<int>> affs;
	REP(i, n) affs.pb(set<int>{i});
	set<int> testAffs;
	REP(i, n/2) {
		int dist = min(i, n-i-1);
		if(((n & (1<<dist))) != 0) {
			testAffs.insert(i);
		}
	}
	REP(i, n-1) {
		string seqNext(n-i, '0');
		vector<set<int>> nextAffs(n-i-1);
		REP(j, n-i-1) {
			int a = seq[j]-'0';
			int b = seq[j+1]-'0';
			int ans = abs(a-b);
			seqNext[j] = ans+'0';
			for(int t : affs[j]) {
				if(!affs[j+1].count(t))
					nextAffs[j].insert(t);
			}
			for(int t : affs[j+1]) {
				if(!affs[j].count(t))
					nextAffs[j].insert(t);
			}
		}
		seqNext[n-i-1] = '\0';
		seq = seqNext;
		affs = nextAffs;
	//	cout << seqNext << endl;
	}
//	cout << "AFFS [n=" << n << "]: ";
//	for(int x : affs[0]) cout << x << " ";
//	cout <<endl;
	return seq[0]-'0';
}
int solveFast(istream& cin, ostream& cout) {
	cin >> n;
	string seq;
	cin >> seq;
	int pairDiffs = 0;
	int oneThrees = 1;
	REP(i, n) {
		seq[i]--;
		if(seq[i] == '1') {
			oneThrees = 0;
		}
	}
	if(oneThrees)REP(i, n) seq[i] = seq[i]== '2' ? '1' : seq[i];
	int div2 = 0;
	int total = 0;
	REP(i, n) {
		if(div2 == 0) {
			total = (total+seq[i]-'0')%2;
//			cout << i << endl;
		} //else cout << i << " has div2 " << div2 << endl;

		int nxtTop = n-1-i;
		while(nxtTop > 0 && (nxtTop&1)==0)
			div2++, nxtTop >>= 1;
		int nxtBot = i+1;
		while(nxtBot > 0 && (nxtBot&1)==0)
			div2--, nxtBot >>= 1;
	}

	return oneThrees ? 2*total : total;
}
 /*
1 1 0
0 1
1
0 0 -> 0
0 1 -> 1
0 2 -> 2
1 1 -> 0
1 2 -> 1
2 2 -> 0
*/
/*
abcdefg
a-b, b-c, c-d, d-e, e-f, f-g
a-c, b-d, c-e, d-f, e-g
a-b-c+d,b-c-d+e,c-d-e+f,d-e-f+g
a+e, b+f, c+g
a+b+e+f, b+c+f+g
a+c+e+g


*/

int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cout << solveFast(cin, cout) << endl;
  
	return 0;
}


Measured memory_bytes: 1948