n = int(input()) p = list(map(int, input().split())) ans = 0 if n == 2: if p[0] == 1: ans = 0 else: ans = 1 else: for i in range(n): if p[i] == 1: if p[(i+1)%n] == 2: ans = min(i, n-i+2) else: ans = min(n-i,i+2) print(ans)
n = int(input()) p = list(map(int, input().split())) ans = 0 if n == 2: if p[0] == 1: ans = 0 else: ans = 1 else: for i in range(n): if p[i] == 1: if p[(i+1)%n] == 2: ans = min(i, n-i+2) else: ans = min(n-i,i+2) print(ans)