import sys



lst = []

for line in sys.stdin:

    num = line.strip()

    if num == "0":

        print(lst.pop())

    else:

        lst.append(num)
import sys



lst = []

for line in sys.stdin:

    if line.strip() :

        num = int(line.strip())

        if num == 0:

            print(lst.pop())

        else:

            lst.append(num)
import sys

lst = []
for line in sys.stdin:
    num = line.strip()
    if num == "0":
        print(lst.pop())
    else:
        lst.append(num)

import sys

lst = []
for line in sys.stdin:
    if line.strip():
        num = int(line.strip())
        if num == 0:
            print(lst.pop())
        else:
            lst.append(num)

-    num = line.strip() -    if num == "0": -        print(lst.pop()) -    else: -        lst.append(num) +    if line.strip(): +        num = int(line.strip()) +        if num == 0: +            print(lst.pop()) +        else: +            lst.append(num)