#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <map>

using namespace std;
  
set<int> q; //мн-во, с которым мы работаем
typedef set<int>::iterator Q_ITER;
typedef set<int>::reverse_iterator Q_REV_ITER;
map<int, int, less<int> > s; //интервалы
typedef map<int, int, less<int> >::iterator S_ITER;
int n;

int main() {

  char t;
  int x,prev_x,after_x;
  Q_ITER it1,it2;
  Q_REV_ITER rit;
  S_ITER sit;

//  freopen("nearnum.in","r",stdin);
//  freopen("nearnum.out","w",stdout);
  scanf("%d\n",&n);
  for (int i=0; i<n; i++) {
    scanf("%c",&t);
    switch(t) {
      case 'A' : //ADD
        scanf("%*c%*c %d\n", &x);
        if (q.count(x) > 0) continue;
        prev_x=after_x=-1;
        it2 = q.upper_bound(x); //элемент после x
        if (it2 != q.end()) {
           after_x = *it2;
           it1 = it2;
           if (it1!=q.begin())
           {
             it1--;
             prev_x = *it1;
           }  
        } else
        {
          rit = q.rbegin();
          if (rit != q.rend()) prev_x = *rit;
        }
        q.insert(x);
        if (prev_x>=0)
          s[x-prev_x]++; //интервал число перед x - x
        if (after_x>=0)
          s[after_x-x]++; //интервал x - число после x
        break;
      case 'D' : //DEL
        scanf("%*c%*c %d\n", &x);
        prev_x=after_x=-1;
        it1=q.find(x); it2=q.find(x);
        if (it1==q.end()) continue;
        it1--; it2++;
        if (it1!=q.end() && *it1 != x) {
          prev_x = *it1;
          sit = s.find(x-prev_x);
          sit->second--;
          if (sit->second==0)
            s.erase(sit);
        }
        if (it2!=q.end()) {
          after_x = *it2;
          sit = s.find(after_x-x);
          sit->second--;
          if (sit->second==0)
             s.erase(sit);
        }
        q.erase(x);
        if (prev_x>=0 && after_x>=0)
          s[after_x-prev_x]++;
        break;
      case 'F' : //FIND
        scanf("%*c%*c%*c\n");
        sit = s.begin();
        cout << sit->first << endl;
    }
  }
  return 0;
}

