n = int(input()) A = list(map(int, input().split())) for i in range(3): X = [i, (i + 1) % 3, (i + 2) % 3] for _ in range(n - 1): X.append(X[-2]) X.append(X[-4]) if A == X: print(2 - n % 2) exit() for i in range(3): X = [i, (i - 1) % 3, (i - 2) % 3] for _ in range(n - 1): X.append(X[-2]) X.append(X[-4]) if A == X: print(1 + n % 2) exit() print(0)