def fnc(d,n=0): if d[0] == min(d): print(n) else: x = d[0]-1 d.remove(x) d.insert(0,x) fnc(d, n+1) input() fnc(list(map(int,input().split(" "))))