#include <iostream>
#include <stack>
using namespace std;

int main(void){
	double n;
	stack <double> buf;

	while (true){
		cin>>n;
		if (cin.eof()) break;

		if (n!=0) buf.push(n);
		else{
			cout<<buf.top()<<endl;
			buf.pop();
		}
	}
    return 0;
}