#include　<iostream>
#include <array>

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num==0) pop();
		else push(num);
	}

    return 0;
}

