Bn = list(map(int, input().split())) ans = 0 index = 1 for bi in Bn: if bi != index: ans = bi - 1 break index += 1 print(ans)