""" https://yukicoder.me/problems/no/1717 すぐに0だけになる? """ N = int(input()) A = list(map(int,input().split())) while len(A) >= 2: B = [] for i in range(len(A)-2): tup = (A[i],A[i+1],A[i+2]) if tup in ( (0,1,2),(1,2,0),(2,0,1) ): B.append(1) elif tup in ( (2,1,0),(1,0,2),(0,2,1) ): B.append(2) else: B.append(0) if sum(B) == 0: B = [0] A = B print (A[0])