def aux(f)
  p=[]   # inbetween
  q=[]   # output
  while f.length > 0
    x=f.shift
    if (x=="0")
      q.push(p.pop)
    else
      p.push(x)
    end
  end
  q
end

def main
  fh=STDIN
  #fh=File.new("vol0-0013.txt", "r")
  seq=[]
  while fh.gets
    seq.push($_.chomp)
  end
  puts aux(seq)
end

if $0 == __FILE__ then
  main
end
