#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <iomanip>

using namespace std;


int main(void)
{
	int a[100], g = 0,co = 0;

	while (cin >> g)
	{
		if (g != 0)
		{
			co++;
			a[co] = g;
		}
		else
		{
			cout << a[co] << endl;
			a[co] = 0;
			co--;
		}
	}
	return 0;
}


