//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////


ll cal(vector<ll>v){
    ll n=v.size();
    if(n==1)return v[0];
    vector<ll>w;
    rep(i,0,n-2){
        w.pb(abs(v[i+1]-v[i]));
    }
    return cal(w);
}
vector<ll>calv(vector<ll>v){
    ll n=v.size();
    vector<ll>w;
    rep(i,0,n-2){
        w.pb(abs(v[i+1]-v[i]));
    }
    return w;
}


vector<l_l>compress(vector<ll>v){
    vector<l_l>res;
    ll n=v.size();
    rep(i,0,n-1){
        ll c=1;
        while(i<=n-2&&v[i]==v[i+1]){
            c++;
            i++;
        }
        res.pb({v[i],c});
    }
    return res;
}
ll calcomv(vector<l_l>v){
    if(v.size()==1){
        return 0;
    }
    if(v.size()==2){
        ll n=v[0].se+v[1].se;
        ll a[n];
        rep(i,0,v[0].se-1)a[i]=0;
        rep(i,v[0].se,n-1)a[i]=1;
        ll c[n];
        c[0]=1;
        rep(i,1,n-1){
            c[i]=c[i-1]*(n-i)/i;
        }
        ll sum=0;
        rep(i,0,n-1){
            sum+=(c[i]%2)*a[i];
        }
        sum%=2;
        ll zz=abs(v[0].fi-v[1].fi);
        return sum*zz;
    }
    vector<ll>res;
    ll n=v.size();
    rep(i,0,n-1){
        if(v[i].se>=2)res.pb(0);
        if(i!=n-1)res.pb(abs(v[i].fi-v[i+1].fi));
    }
    vector<l_l>x=compress(res);
    return calcomv(x);
}


ll N=10;
void dfs(vector<ll>v,ll k){
    if(k==N){
        //for(auto x:v)cout<<x<<" ";cout<<":";
        cout<<cal(v);
        if(cal(v)!=calcomv(compress(v))){
            for(auto x:v)cout<<x<<" ";
        }cout<<endl;
        return;
    }
    rep(i,0,1){
        vector<ll>w;
        for(auto x:v)w.pb(x);
        w.pb(i);
        dfs(w,k+1);
    }
}
ll kai(ll n){
    ll res=0;
    while(n>0&&n%2==0){
        res++;
        n/=2;
    }
    return res;
}
int main(){fastio
    //vector<ll>v;
    //dfs(v,0);
    
    ll n;cin>>n;
    string s;cin>>s;
    ll b[n];
    bool flag=true;
    rep(i,0,n-1){
        b[i]=s[i]-'1';
        if(b[i]==1)flag=false;
    }
    ll a[n];
    if(flag){
        rep(i,0,n-1)a[i]=b[i]/2;
    }else{
        rep(i,0,n-1)a[i]=b[i]%2;
    }
    ll c[n];c[0]=1;
    ll d[n];d[0]=0;
    rep(i,1,n-1){
        //c[i]=c[i-1]*(n-i)/i;
        d[i]=d[i-1]+kai(n-i)-kai(i);
    }
    //cout<<"d ";rep(i,0,n-1)cout<<d[i]<<" ";cout<<endl;
    //cout<<"a ";rep(i,0,n-1)cout<<a[i]<<" ";cout<<endl;
    ll sum=0;
    rep(i,0,n-1){
        //sum+=(c[i]%2)*a[i];
        if(d[i]==0)sum+=a[i];
    }
    sum%=2;
    if(flag){
        cout<<sum*2<<endl;
    }else{
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 24860