#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstdio>

int main(void)
{
  std::vector<int> in, out;

  while (true) {
    int value;
    std::cin >> value;
    if (value == 0) {
      std::vector<int>::iterator it = in.end() - 1;
      out.push_back(*it);
      in.erase(it);
    }
    else {
      in.push_back(value);
    }
    if (in.size() == 0) {
      break;
    }
  }

  for (std::vector<int>::iterator it = out.begin(); it != out.end(); ++it) {
    std::cout << *it << std::endl;
  }

  return 0;
}