import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.file;
import std.math;

int main() {
	string l;
	int[] stack;
	while((l = readln(), l.length)){
		l = l.split("\n")[0];
		
		if(!l.length || !l.split[0].length) break;
		int a = to!int(l.split[0]);
		
		if(a > 0) stack ~= a;
		else printf("%d\n", stack[$-1]), stack = stack[0..$-1];
		}
	return 0;
	}