class Stack {
  private int top;
  private int val[];


  public Stack(int size) {
    val = new int [size];
    top = -1;
  }

  public void push(int x) {
    if (!isFull()){
      val[++top] = x;
    } else 
      throw new RuntimeException("Stack overflow");
  }
  
  public int pop() {
    if (!isEmpty())
      return val[top--];
    else throw new RuntimeException("Stack underflow");
  }

  public void print(){
    for (int i = top; i>= 0; i--) 
      System.out.println(val[i]+" ");
  }
  
  public boolean isEmpty() {return top == -1;}

  private boolean isFull() {return top >= val.length-1;}

  public static void main(String[] args){
    Stack s = new Stack(10);
    System.out.println(s.pop());
  }
}

