N = int(input()) a = list(map(int,input().split())) an = [a.index(i+1) for i in range(N)] i = N-1 t = 0 count = 0 while True: if an[i] < an[i-1]: an = list(map(lambda x: x+1 if x <= i else x, an)) an[i-1] = 0 count += 1 t = 1 if i > 1: i -= 1 else: if t == 0: break else: t = 0 i = N-1 print(count)