#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 1000000001
#define EPS 1.0e-6

using namespace std;

typedef long long ll;

int main()
{
	stack<int> s;

	int n;
	while (cin >> n) {
		if (n != 0)s.push(n);
		else {
			cout << s.top() << endl;
			s.pop();
		}
	}

	return 0;
}