using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    private int N;
    private int[] A;


    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.NextCharArray().Select(c => c - '0' - 1).ToArray();

        // 答えが奇数になるか?
        // いっこしたが奇数になる
        // 隣合う数の偶奇が違う

        if (IsOne())
        {
            Console.WriteLine(1);
            return;
        }

        // 答えは 0 or 2
        // 1がある 最後まで2を残せない 0

        if (A.Contains(1))
        {
            Console.WriteLine(0);
            return;
        }

        // 答えが2になるか
        // いっこしたが2になる
        // 隣合う2数が 0,2 or 2,0

        if (IsTwo())
        {
            Console.WriteLine(2);
            return;
        }

        Console.WriteLine(0);
    }

    bool IsTwo()
    {
        int[] two = new int[N];
        two[0] = 0;
        for (int i = 1; i < N; i++)
        {
            int cnt = 0;
            int t = i;
            while (t % 2 == 0)
            {
                cnt++;
                t /= 2;
            }

            two[i] = two[i - 1] + cnt;
        }

        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            int cnt = two[N - 1] - (two[i] + two[N - 1 - i]);
            if (A[i] == 2 && cnt == 0) ans++;
            ans %= 2;
        }

        return ans == 1;
    }

    // 答えが1になるか?
    bool IsOne()
    {
        // cnt[i] = N-1 C i = (N-1)! / (N-i-1)! i!
        // N-1に偶数

        // i!は2でn回割り切れる
        int[] two = new int[N];
        two[0] = 0;
        for (int i = 1; i < N; i++)
        {
            int cnt = 0;
            int t = i;
            while (t % 2 == 0)
            {
                cnt++;
                t /= 2;
            }

            two[i] = two[i - 1] + cnt;
        }

        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            int cnt = two[N - 1] - (two[i] + two[N - 1 - i]);
            if (A[i] % 2 == 1 && cnt == 0) ans++;
            ans %= 2;
        }

        return ans == 1;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 34756