s=[];a=0 for _ in'.'*int(input()): p=len(s);i=int(input()) while s and s[-1]