package com.company;

import com.company.lec1.stacks.StacksOfStrings;

import java.io.PrintStream;
import java.util.Scanner;

public class Main {

    private static void StacksOfStrings(Scanner in, PrintStream out){
        StacksOfStrings stack = new StacksOfStrings();
        while(in.hasNext()) {
            String s = in.next();
            if ((s.equals("-"))){
                out.print(stack.pop() + " ");

            }
            else {
                stack.push(s);
            }
        }
    }

    private static void StacksOfItems(Scanner in, PrintStream out){
        StacksOfItems stack = new StacksOfItems();
        while(in.hasNext()) {
            String s = in.next();
            if ((s.equals("-"))){
                out.print(stack.pop() + " ");

            }
            else {
                stack.push(s);
            }
        }
    }

    public static void main(String[] args) {
	// write your code here
        Scanner in = new Scanner(System.in);
        PrintStream out = System.out;
    StacksOfStrings(in, out);
    }

}
