#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Mint {
    using u64 = std::uint_fast64_t;
    u64 Modulus = MOD;

public:
    u64 a;

    constexpr Mint(const u64 x = 0) noexcept : a(x % Modulus) {}

    constexpr u64 &value() noexcept { return a; }

    constexpr const u64 &value() const noexcept { return a; }

    constexpr Mint operator+(const Mint rhs) const noexcept {
        return Mint(*this) += rhs;
    }

    constexpr Mint operator-(const Mint rhs) const noexcept {
        return Mint(*this) -= rhs;
    }

    constexpr Mint operator*(const Mint rhs) const noexcept {
        return Mint(*this) *= rhs;
    }

    constexpr Mint operator/(const Mint rhs) const noexcept {
        return Mint(*this) /= rhs;
    }

    constexpr Mint &operator+=(const Mint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }

    constexpr Mint &operator-=(const Mint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }

    constexpr Mint &operator*=(const Mint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }

    constexpr Mint &operator/=(Mint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }

    constexpr Mint pow(int rhs) noexcept {
        Mint ret(1);
        Mint base(a);
        u64 exp = static_cast<u64>(rhs);
        while (exp) {
            if (exp % 2) {
                ret *= base;
            }
            base *= base;
            exp /= 2;
        }
        return ret;
    }

};


class Combination {
public:
    vector<Mint> fact;
    vector<Mint> ifact;

    Combination(int n) {
        fact.resize(static_cast<unsigned long>(n + 1));
        ifact.resize(static_cast<unsigned long>(n + 1));

        fact[0] = ifact[0] = Mint(1);
        for (int i = 1; i <= n; ++i) {
            fact[i] = fact[i - 1] * Mint(i);
            ifact[i] = Mint(1) / fact[i];
        }
    }

    Mint nPk(Int n, Int k) {
        return fact[n] * ifact[n - k];
    }

    Mint nCk(Int n, Int k) {
        return fact[n] * ifact[n - k] * ifact[k];
    }

    Mint nHk(Int n, Int k) {
        return nCk(n + k - 1, k - 1);
    }
};


Combination cmb(123456);

class Solve {
public:
    vector<Int> waru;

    void init() {
        waru.resize(1004567);
        for (int i = 0; i < waru.size(); ++i) {
            Int k = i;
            Int cnt = 0;
            while (k > 0 && k % 2 == 0) {
                if (k % 2 == 0) {
                    cnt++;
                }
                k /= 2;
            }
            waru[i] = cnt;
        }
        for (int i = 0; i + 1 < waru.size(); ++i) {
            waru[i + 1] += waru[i];
        }
    }

    void solve(Int N, vector<Int> A) {
//        init();


//        Int N;

//        vector<Int> A;


        set<Int> app;
        for (auto e : A) app.insert(e);

        Int ans = func(A);
        if (!app.count(2)) {
            vector<Int> B;
            for (int i = 0; i + 1 < A.size(); ++i) {
                B.push_back(0);
                B[i] = abs(A[i] - A[i + 1]) / 2;
            }
//            ans *= 2;
            ans = func(B) * 2;
        }
        cout << ans << endl;


//        if (ans != jikken(A)) {
//            exit(-1);
//        }

    }

    Int nck(Int n, Int k) {
        Int val = waru[n] - waru[n - k] - waru[k];
        return val == 0;
    }

    Int func(vector<Int> A) {
        if (A.size() == 1) return A[0];

        for (int i = 0; i < A.size(); ++i) {
            A[i] %= 2;
        }
        Int n = A.size();

        Int ret = 0;
        for (int i = 0; i < n; ++i) {
            Int kei = nck(n - 1, i);
            Int tmp = kei * A[i];
            ret += tmp;
        }
        return ret % 2;


    }


    Int jikken(vector<Int> A) {
        Int N = A.size();
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N - i; ++j) {
                cout << A[j] << "";

                if (j + 1 < (N - i)) {
                    A[j] = abs(A[j + 1] - A[j]);
                }
            }
            cout << endl;
        }

        return A[0];
    }

};

void gene(Int n) {
    srand(233);
    cout << n << endl;
    rep(i, 0, n) {
        cout << rand() % 3 + 1;
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);


    bool debug = true;
    debug = false;
    Solve solve;
    solve.init();
    if (!debug) {
        Int N;
        cin >> N;
        string s;
        cin >> s;
        vector<Int> A;
        for (auto e : s) {
            A.push_back(e - '0');
        }
        solve.solve(N, A);

    } else {
        while (true) {
            Int N = rand() % 100 + 2;
//            Int N = 1000000;
            vector<Int> A;
            cout << N << endl;
            rep(i, 0, N) {
                A.push_back(rand() % 3 + 1);
                cout << A[i] << " ";
            }
            cout << endl;
            solve.solve(N, A);

            cout << endl;
        }

    }

//    gene(1000);


    return 0;
}


Measured memory_bytes: 45024