#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<unordered_map>
#include<stack>
#include<random>
#include <chrono>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
#include<fstream>
#include<random>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=9223372036854775807;
const ll mod=998244353;
int  MOD(int  a, int  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
ll  max3(ll  a,ll  b, ll  c)
{
    return max(c,max(a,b));
}
ll min3(ll  a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y,ll mod1)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod1;
        y = y>>1;
        x = (x*x)%mod1;
    }
    return res;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x,ll p)
{
    return power(x,p-2,p);
}
struct point
{
    ll x;ll y;
};
ll cross(point a,point b)
{
    return a.x*b.y-b.x*a.y;
}
bool ccw(point p1,point p2)
{
    /* point n1;n1.x=p1.x-p0.x;n1.y=p1.y-p0.y;
     point n2;n2.x=p2.x-p0.x;n2.y=p2.y-p0.y;*/
    if(cross(p1,p2)>0)
    {
        return true;
    }
    else
    {
        return false;
        //No need to worry about cross=0 case in this question;
    }
}
void ccw_sort(vector<point> &v)
{
    vector<point> v1,v2;
    for(int i=0;i<v.size();i++)
    {
        if(v[i].y>0)
        {
            v1.push_back(v[i]);
        }
        else
        {
            v2.push_back(v[i]);
        }
    }
    sort(all(v1),ccw);
    sort(all(v2),ccw);
    for(int i=0;i<v2.size();i++)
    {
        v1.push_back(v2[i]);
    }
    v=v1;
}
int main()
{
    fastio;
    int n;
    cin>>n;
    vi a(n);
    string str;
    cin>>str;
    for(int i=0;i<n;i++)
    {
        a[i]=str[i]-'0';
    }
    vll fac(n+1);
    vll fac1(n+1);
    fac[0]=0;
    fac[1]=0;
    fac1[0]=0;
    fac1[1]=0;
    for(int j=2;j<=n;j++)
    {
        ll x=j;
        int cnt=0;
        while(x%2==0)
        {
            x=x/2;
            cnt++;
        }
        fac[j]=fac[j-1]+cnt;
    }
    for(int j=2;j<=n;j++)
    {
        ll x=j;
        int cnt=0;
        while(x%3==0)
        {
            x=x/3;
            cnt++;
        }
        fac1[j]=fac1[j-1]+cnt;
    }
    for(int j=0;j<4;j++)
    {
        if(a.size()==1)
        {
            break;
        }
        vi temp;temp.resize((int)a.size()-1);
        for(int j=0;j<((int)a.size())-1;j++)
        {
            temp[j]=abso((ll)a[j+1]-a[j]);
        }
        a=temp;
    }
    if(a.size()==1)
    {
        cout<<a[0]<<endl;
    }
    else
    {
        ll ans=0;
        for(int j=0;j<a.size();j++)
        {
            ll up=fac[(int)a.size()-1];
            ll d1=fac[(int)a.size()-1-j];
            ll d2=fac[j];
            if(up-d1-d2>0)
            {
                ans=(ans)%2;
            }
            else
            {
                ans=(ans+(a[j]))%2;
            }
        }
        if(ans%2==1){
        cout<<ans<<endl;
        }
        else
        {
            int num_2=0;
            int num_1=0;
            for(int j=0;j<a.size();j++)
            {
                if(a[j]==1)
                {
                    num_1++;
                }
                if(a[j]==2)
                {
                    num_2++;
                }
            }
            if(num_1*num_2>0)
            {
                cout<<0<<endl;
            }
            else
            {
                if(num_2==0){
                cout<<ans<<endl;
                }
                else
                {
                    ans=0;
                    for(int j=0;j<a.size();j++)
                    {
                        ll up=fac[(int)a.size()-1];
                        ll d1=fac[(int)a.size()-1-j];
                        ll d2=fac[j];
                        if(up-d1-d2>0)
                        {
                            ans=(ans)%2;
                        }
                        else
                        {
                            ans=(ans+(a[j]/2))%2;
                        }
                    }
                    if(ans%2==0)
                    {
                        cout<<0<<endl;
                    }
                    else
                        
                    {
                        cout<<2<<endl;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 24860