#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){

  int A[2000000], i, cnt= 0, Max = 0, c = 0, Max2=0;
  char C[8];

  while(scanf("%s", C)==1){
    if(C[0] == 'i'){
      for(i=cnt; i>0; i--){
        A[i] = A[i-1];
      }
      scanf("%d", &A[0]);
      if(Max < A[0]) Max = A[0];
      cnt ++;
    }
    else if(strncmp(C, "ex", 2) == 0){
      printf("%d\n", Max);
      for(i=0; i<cnt; i++){
        if(Max2 < A[i] && A[i] < Max){
          Max2 = A[i];
        }
        if(A[i]==Max && c == 0){
          A[i] = A[i+1];
          c = 1;
        }
        else if(c == 1){
          A[i] = A[i+1];
        }
      }
      Max = Max2;
      Max2 = 0;
      c = 0;
      cnt--;
    }
    else break;
  }
return 0;
}



