import strutils, sequtils, algorithm var N = stdin.readLine.parseInt a = stdin.readLine.split.map parseInt cnt_S = int.high cnt_L = int.low if a != a.sorted(cmp): for a_i in a: if a_i == 1: break cnt_S = min(cnt_S, a_i) for a_i in a.reversed: if a_i == N: break cnt_L = max(cnt_L, a_i) echo max(cnt_L, N - cnt_S) else: echo 0