You are given a sequence of N digits, where each element is 1, 2, or 3. Define x_{i,j} as follows: x_{1,j} = a_j (1 ≤ j ≤ N), x_{i,j} = | x_{i-1,j} - x_{i-1,j+1} | (2 ≤ i ≤ N and 1 ≤ j ≤ N+1-i). Find x_{N,1}. Constraints: 2 ≤ N ≤ 10^6, a_i = 1,2,3 (1 ≤ i ≤ N). Input is given as N and a_1a_2...a_N. Output x_{N,1}. Example: Input: 4, 1231; Output: 1.

# Buggy version:
n = int(input())
al = list(input())

al = [int(a) - 1 for a in al]
flag = False
if 1 not in al:
    flag = True
    al = [a // 2 for a in al]
else:
    al = [a if a != 2 else 0 for a in al]

countl = [0]
a = 0
for i in range(1, n+1):
    if i % 2 == 0:
        a += 1
    countl.append(a)

def comb(a,b):
    if countl[a] - countl[a-b] - countl[b] > 0:
        return 0
    else:
        return 1

ans = 0
for idx, a in enumerate(al):
    if a == 1:
        ans += comb(n-1, idx)

if ans % 2 == 0:
    print(0)
else:
    if flag:
        print(2)
    else:
        print(1)



# Fixed version:
n = int(input())
al = list(input())

al = [int(a) - 1 for a in al]
flag = False
if 1 not in al:
    flag = True
    al = [a // 2 for a in al]
else:
    al = [a if a != 2 else 0 for a in al]

countl = [0]
a = 0
for i in range(1, n+1):
    while i % 2 == 0:
        a += 1
        i //= 2
    countl.append(a)

def comb(a,b):
    if countl[a] - countl[a-b] - countl[b] > 0:
        return 0
    else:
        return 1

ans = 0
for idx, a in enumerate(al):
    if a == 1:
        ans += comb(n-1, idx)


if ans % 2 == 0:
    print(0)
else:
    if flag:
        print(2)
    else:
        print(1)

# Buggy version:
N = int(input())
a = [ int(s) - 1 for s in input()]

# r! に含まれる 2 の数
twos = {}
twos[0] = 0
for r in range(1, N):

    count = 0
    tmp = r
    while tmp % 2 != 0:
        tmp //= 2
        count += 1
    
    twos[r] = twos[r-1] + count

# {N-1}_C_r の偶数奇数判定
ncr = {}
for r in range(N):
    if twos[N-1] - twos[N-1-r] - twos[r] > 0:
        ncr[r] = 0
    else:
        ncr[r] = 1

# 答えの判定
oe = 0
for r, ai in enumerate(a):
    oe = (oe + ncr[r] * ai) % 2

if oe == 1:
    print(1)
else:
    if 1 in a:
        print(0)
    else:
        print(2)


# Fixed version:
N = int(input())
a = [ int(s) - 1 for s in input()]

# r! に含まれる 2 の数
twos = {}
twos[0] = 0
for r in range(1, N):

    count = 0
    tmp = r
    while tmp % 2 == 0:
        tmp //= 2
        count += 1
    
    twos[r] = twos[r-1] + count


# {N-1}_C_r の偶数奇数判定
ncr = {}
for r in range(N):
    if twos[N-1] - twos[N-1-r] - twos[r] > 0:
        ncr[r] = 0
    else:
        ncr[r] = 1


# 答えの判定
oe = 0
for r, ai in enumerate(a):
    oe = (oe + ncr[r] * ai) % 2

if oe == 1:
    print(1)
else:
    if 1 in a:
        print(0)
    else:
        oe2 = 0
        for r, ai in enumerate(a):
            oe2 = (oe2 +ncr[r] * ai // 2 ) %2
        if oe2 == 1:
            print(2)
        else:
            print(0)

# Buggy version:
N = int(input())
a = list(map(int,list(input())))
a = list(map(lambda x:x-1,a))
x = 0
num_mod = [0]*N
for i in range(1,N):
  x = 0
  while i%2==0:
    i//=2
    x+=1
  num_mod[i] = num_mod[i-1]+x
  

for i,n in enumerate(a):
  if n%2==0:
    continue
  else:
    if num_mod[N-1]==(num_mod[i]+num_mod[N-1-i]):
      x+=1

if x%2!=0:
  print(1)
  
elif 1 in a:
  print(0)

else:
  a = [x//2 for x in a]
  x = 0
  for i,n in enumerate(a):
    if n%2==0:
      continue
    else:
      if num_mod[N-1]==(num_mod[i]+num_mod[N-1-i]):
        x+=1
  if x%2!=0:
    print(2)
  else:
    print(0)


# Fixed version:
N = int(input())
a = list(map(int,list(input())))
a = list(map(lambda x:x-1,a))
x = 0
num_mod = [0]*N
for i in range(1,N):
  tmp = 0
  t = i
  while t%2==0:
    t//=2
    tmp+=1
  num_mod[i] = num_mod[i-1]+tmp
  
for i,n in enumerate(a):
  if n%2==0:
    continue
  else:
    if num_mod[N-1]==(num_mod[i]+num_mod[N-1-i]):
      x+=1

if x%2!=0:
  print(1)
  
elif 1 in a:
  print(0)

else:
  a = [x//2 for x in a]
  x = 0
  for i,n in enumerate(a):
    if n%2==0:
      continue
    else:
      if num_mod[N-1]==(num_mod[i]+num_mod[N-1-i]):
        x+=1
  if x%2!=0:
    print(2)
  else:
    print(0)

# Buggy version:
def pascal_parity(N):
    if N & -N == N:
        return [1] * N
    else:
        n = N - (1<<(N.bit_length()-1))
        p = pascal_parity(n)
        return p + [0]*(N-2*n) + p

N = int(input())
A = list(map(int, input()))
if 1 in A:
    if sum(A) % 2 == 1:
        print(1)
    else:
        print(0)
else:
    P = pascal_parity(N)
    pa = 0
    for p, a in zip(P, A):
        if p==1 and a==2:
            pa += 1
    if pa % 2 == 1:
        print(2)
    else:
        print(0)


# Fixed version:
def pascal_parity(N):
    if N & -N == N:
        return [1] * N
    else:
        n = N - (1<<(N.bit_length()-1))
        p = pascal_parity(n)
        return p + [0]*(N-2*n) + p

N = int(input())
A = list(map(lambda x: int(x)-1, input()))
P = pascal_parity(N)
if 1 in A:
    if sum(a*p for a,p in zip(A, P)) % 2 == 1:
        print(1)
    else:
        print(0)
else:
    pa = 0
    for p, a in zip(P, A):
        if p==1 and a==2:
            pa += 1
    if pa % 2 == 1:
        print(2)
    else:
        print(0)