#define scanf_s scanf
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 150
int main(void)
{
	int w, n, now = 0, cou = 0;
	int list[MAX] = { 0 };
	int li[MAX] = { 0 };
	do{	
		scanf_s("%d", &n);
		if (n != 0) { list[now] = n; ++now; }
		else { --now; 	printf("%d\n", list[now]);}
	} while (now != 0);
}