import numpy as np def conv(xs): n = xs.shape[0] ys = np.zeros(n - 2, dtype=np.int32) d0 = xs[0:-2] - xs[1:-1] d1 = xs[1:-1] - xs[2:] d0 = (d0 + 3) % 3 d1 = (d1 + 3) % 3 ys[(d0 == 1) * (d1 == 1)] = 2 ys[(d0 == 2) * (d1 == 2)] = 1 return ys def main(): n = int(input()) xs = np.array(list(map(int, input().split())), dtype=np.int32) xs = conv(xs) if n == 1: return xs[0] # 1 0 2 0 1 0 2 0 1 # 2 0 1 0 2 0 1 r = (len(xs) - 1) // 2 if not np.all(xs[1::2] == 0): return 0 if ( np.all(xs[0::4] == 1) and np.all(xs[2::4] == 2) ) or ( np.all(xs[0::4] == 2) and np.all(xs[2::4] == 1) ): if r % 2 == 0: return xs[0] else: return 3 - xs[0] return 0 print(main())