old = int(input()) k=1 i = int(input()) while(i != 0): if(i>old): print(i) k+=1 break else: old = i i = int(input()) if(k!=2): print(old)