import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;

void main()
{
  string input;
  int num;
  int[] train;

  while ((input = readln().chomp()).length != 0) {
    num = input.to!int();
    if (num == 0) {
      writeln(train[$ - 1]);
      train.length--;
    } else {
      train ~= num;
    }
  }
}