import std.stdio, std.conv, std.algorithm, std.string, std.container;

void main(){
    SList!int list;
    while(true){
        auto line = readln.chomp;
        if(line.length == 0){
            break;
        }
        auto input = line.to!int;
        if(input){
            list.insertFront(input);
        }else{
            list.front.writeln;
            list.removeFront;
        }
    }
}