import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    int[] b;
    foreach(s;stdin.byLine())
    {
        immutable n = s.chomp().to!int;
        if(n) b~=n;
        else writeln(b.back),b.popBack();
    }
}