var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  main(input);
});

function main(input) {
  var stack = [];
  input = input.split('\n');
  input.forEach(function(number) {
    if (number === '0') {
      console.log(stack.pop());
    } else {
      stack.push(number);
    }
  });
}