//
// Written by Fyodor Menshikov 10.03.2009
// 11:58-12:57
//

import java.io.*;
import java.util.*;

class Scanner {

   StreamTokenizer in;

   Scanner(Reader r) {
      in = new StreamTokenizer(new BufferedReader(r));
   }

   void asserT(boolean e) {
      if (!e) {
         throw new Error();
      }
   }

   int nextInt() {
      try {
         in.nextToken();
         asserT(in.ttype == in.TT_NUMBER);
         int value = (int)in.nval;
         asserT(value == in.nval);
         return value;
      } catch (IOException e) {
         throw new Error(e);
      }
   }

   String next() {
      try {
         in.nextToken();
         asserT(in.ttype == in.TT_WORD);
         return in.sval;
      } catch (IOException e) {
         throw new Error(e);
      }
   }
}

class Set {

   int low;
   int high;
   int size = 0;
   Set left = null;
   Set right = null;
   int values[] = new int[64];

   int lastMin;
   int lastMax;
   int lastDist;
   boolean lastMinValid = false;
   boolean lastMaxValid = false;
   boolean lastDistValid = false;

   Set(int low, int high) {
      this.low = low;
      this.high = high;
   }

   void asserT(boolean e) {
      if (!e) {
         throw new Error();
      }
   }

   boolean add(int value) {
      lastMinValid = false;
      lastMaxValid = false;
      lastDistValid = false;
      asserT(low <= value && value <= high);
      if (values != null && size < values.length) {
         asserT(left == null);
         asserT(right == null);
         for (int i = 0; i < size; i++) {
            if (values[i] == value) {
               return false;
            }
         }
         int i = size;
         while (i > 0 && values[i - 1] > value) {
            values[i] = values[i - 1];
            i--;
         }
         asserT(i == 0 || values[i - 1] < value);
         values[i] = value;
         size++;
         return true;
      }
      if (values != null) {
         asserT(size == values.length);
         asserT(left == null);
         asserT(right == null);
         left = new Set(low, (low + high) / 2);
         right = new Set((low + high) / 2 + 1, high);
         for (int i = 0; i < size; i++) {
            if (values[i] <= (low + high) / 2) {
               left.add(values[i]);
            } else {
               right.add(values[i]);
            }
         }
         values = null;
      }
      asserT(left != null);
      asserT(right != null);
      boolean done;
      if (value <= (low + high) / 2) {
         done = left.add(value);
      } else {
         done = right.add(value);
      }
      if (done) {
         size++;
      }
      return done;
   }

   boolean remove(int value) {
      lastMinValid = false;
      lastMaxValid = false;
      lastDistValid = false;
      asserT(low <= value && value <= high);
      if (values != null) {
         for (int i = 0; i < size; i++) {
            if (values[i] == value) {
               for (int j = i + 1; j < size; j++) {
                  values[j - 1] = values[j];
               }
               size--;
               return true;
            }
         }
         return false;
      }
      asserT(values == null);
      asserT(left != null);
      asserT(right != null);
      boolean done;
      if (value <= (low + high) / 2) {
         done = left.remove(value);
      } else {
         done = right.remove(value);
      }
      if (done) {
         size--;
      }
      return done;
   }

   int findMin() {
      if (!lastMinValid) {
         asserT(size > 0);
         if (values != null) {
            int min = values[0];
            for (int i = 0; i < size; i++) {
               min = Math.min(min, values[i]);
            }
            lastMin = min;
         } else {
            asserT(values == null);
            asserT(left != null);
            asserT(right != null);
            if (left.size > 0) {
               lastMin = left.findMin();
            } else {
               asserT(right.size > 0);
               lastMin = right.findMin();
            }
         }
         lastMinValid = true;
      }
      asserT(lastMinValid);
      return lastMin;
   }

   int findMax() {
      if (!lastMaxValid) {
         asserT(size > 0);
         if (values != null) {
            int max = values[0];
            for (int i = 0; i < size; i++) {
               max = Math.max(max, values[i]);
            }
            lastMax = max;
         } else {
            asserT(values == null);
            asserT(left != null);
            asserT(right != null);
            if (right.size > 0) {
               lastMax = right.findMax();
            } else {
               asserT(left.size > 0);
               lastMax = left.findMax();
            }
         }
         lastMaxValid = true;
      }
      asserT(lastMaxValid);
      return lastMax;
   }

   int findDistance() {
      if (!lastDistValid) {
         asserT(size > 1);
         if (values != null) {
            int dist = values[1] - values[0];
            for (int i = 1; i < size; i++) {
               asserT(values[i] > values[i - 1]);
               dist = Math.min(dist, values[i] - values[i - 1]);
            }
            lastDist = dist;
         } else {
            asserT(values == null);
            asserT(left != null);
            asserT(right != null);
            asserT(left.size + right.size == size);
            int dist = Integer.MAX_VALUE;
            if (left.size > 1) {
               dist = Math.min(dist, left.findDistance());
            }
            if (right.size > 1) {
               dist = Math.min(dist, right.findDistance());
            }
            if (left.size > 0 && right.size > 0) {
               dist = Math.min(dist, right.findMin() - left.findMax());
            }
            lastDist = dist;
         }
         lastDistValid = true;
      }
      asserT(lastDistValid);
      return lastDist;
   }
}

class Main {

   Scanner in;
   PrintWriter out;

   void asserT(boolean e) {
      if (!e) {
         throw new Error();
      }
   }

   void solve() {
      Set set = new Set(1, 1000000000);
      int n = in.nextInt();
      for (int i = 0; i < n; i++) {
         String cmd = in.next();
         if (cmd.equals("ADD")) {
            int value = in.nextInt();
            set.add(value);
         } else if (cmd.equals("DEL")) {
            int value = in.nextInt();
            set.remove(value);
         } else {
            asserT(cmd.equals("FIND"));
            out.println(set.findDistance());
         }
      }
   }

   void run() {
      try {
         in = new Scanner(new InputStreamReader(System.in));
         out = new PrintWriter(System.out);
      } catch (Exception e) {
         throw new Error(e);
      }
      try {
         solve();
      } finally {
         out.close();
      }
   }

   public static void main(String args[]) {
      new Main().run();
   }
}
