#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

/*
struct P {
	int n;
	int l;
};

P ps[1000000];
P qs[1000000];

void print(int m)
{
	FOR_LT(i, 0, m) {
		printf("{%d, %d} ", ps[i].n, ps[i].l);
	}
	printf("\n");
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<int> as(n);
	for (auto& a : as) {
		char c; cin >> c;
		a = c - '0';
	}

	int m = 0;
	// make run length
	{
		int p = abs(as[1] - as[0]);
		int l = 1;
		int j = 0;
		FOR_LT(i, 1, n - 1) {
			int p2 = abs(as[i + 1] - as[i]);
			if (p != p2) {
				ps[j] = { p, l }; j++;
				p = p2;
				l = 1;
			}
			else {
				l++;
			}
		}
		ps[j] = { p, l }; j++;
		m = j;
	}
	//print(m);

	int d = n - 1;
	while (d != 1) {
		//cout << d << endl;
		memcpy(qs, ps, sizeof(P) * d);

		int j = 0, k = 0;
		if (qs[0].l != 1) {
			ps[0].l = qs[0].l - 1;
			ps[0].n = 0;
			j++;
		}
		if (m != 1) {
			ps[j] = { abs(qs[0].n - qs[1].n), 1 };
			j++;
		}
		k++;

		while (k < m) {
			if (qs[k].l != 1) {
				ps[j] = { 0, qs[k].l - 1 };
				j++;
			}
			if (k + 1 != m) {
				int p = abs(qs[k].n - qs[k + 1].n);
				//cout << p << " " << j << " " << k << " " << ps[j - 1].n << endl;

				if (qs[k].l == 1 && ps[j - 1].n == p) {
					ps[j - 1].l++;
				}
				else {
					ps[j] = { p, 1 };
					j++;
				}
			}
			k++;
		}
		m = j;
		d--;
		//print(m);
	}

	cout << ps[0].n << endl;
	
	return 0;
}
*/

int count2(int n) {
	int c = 0;
	while (n != 0) {
		if (n & 1) break;
		c++;
		n >>= 1;
	}
	return c;
}

void construct(int n, vector <bool>& isos) {
	int v = n - 1;
	int64_t c2 = 0;
	isos[0] = false;
	//cout << n << endl;
	FOR_LT(i, 0, v) {
		c2 += count2(v - i);
		c2 -= count2(i + 1);
		if (c2 > 0) isos[i + 1] = true;
		//cout << (v - i) << " " << (i + 1) << " " << c2 << " " << isos[i] << " " << count2(v - i) << " " << count2(i + 1) << endl;
	}
}

void solve1(int n, vector<int>& as)
{
	vector<bool> isos(n);
	construct(n, isos);
	FOR_LT(i, 0, n) {
		if (as[i] == 2) as[i] = 0;
	}

	int64_t c = 0;
	FOR_LT(i, 0, n) {
		if (as[i] == 1 && !isos[i]) c++;
	}
	if (c & 1) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

void solve2(int n, vector<int>& as)
{
	vector<bool> isos(n);
	construct(n, isos);

	int64_t c = 0;
	FOR_LT(i, 0, n) {
		if (as[i] == 2 && !isos[i]) c++;
	}
	if (c & 1) {
		cout << 2 << endl;
	}
	else {
		cout << 0 << endl;
	}
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<int> as(n);
	for (auto& a : as) {
		char c; cin >> c;
		a = c - '1';
	}

	bool has_1 = false;
	for (auto& a : as) {
		if (a == 1) {
			has_1 = true;
			break;
		}
	}

	if (has_1) {
		solve1(n, as);
	}
	else {
		solve2(n, as);
	}
}


Measured memory_bytes: 4352