#include <iostream>
#include <stack>

using namespace std;


int main(){
	stack<char> stk;
	char c;
	while (cin >> c){
		if (c == '0'){
			cout << stk.top() << endl;
			stk.pop();
		}
		else{
			stk.push(c);
		}
	}
	return 0;

}