import java.util.*;
public class MinStack<E extends Comparable<E>> 
				extends ArrayStack<E> {

	private ArrayStack<E> aux;

	public MinStack() {
		super();
		aux = new ArrayStack<>();
	}


	public E min() {
		return aux.peek();
	}

	public void push(E item) {

		super.push(item);
		if(aux.isEmpty() || 
			item.compareTo(aux.peek()) <=0)
				aux.push(item);
	}

	public E pop() {
		if(isEmpty())
	            throw new NoSuchElementException();
		E item = peek();
		if(item.equals(aux.peek()))
			aux.pop();
		return super.pop();
	}


	public static void main(String[] args) {

	    Scanner s  = new Scanner(System.in);

	    MinStack<Integer> stk = new MinStack<>();

	    while(s.hasNextInt()) {
		stk.push(s.nextInt());
	    }

	    while(!stk.isEmpty()) {
		System.out.println(stk.min());
		stk.pop();
	    }
	}
} 
