#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, t;
  int a[100], b[100];
  bool used[100];
  while (cin >> t >> m) {
    memset(a, 0, sizeof(a));
    memset(used, false, sizeof(used));
    int id = 1;
    while (t--) {
      string s;
      cin >> s;
      if (s == "alloc") {
        int cnt = 0, pos = -1;
        int n = 0;
        cin >> n;
        for (int i = 0; i < m; i++) {
          if (a[i] == 0)
            cnt++;
          else
            cnt = 0;
          if (cnt == n) {
            pos = i - n + 1;
            break;
          }
        }
        if (pos == -1)
          puts("NULL");
        else {
          for (int i = 0; i < n; i++) a[pos + i] = id;
          cout << id++ << endl;
        }
      } else if (s == "erase") {
        unsigned int x;
        cin >> x;
        if (x == 0 || x >= id || used[x - 1]) {
          puts("ILLEGAL_ERASE_ARGUMENT");
        } else {
          for (int i = 0; i < m; i++)
            if (a[i] == x) a[i] = 0;
          used[x - 1] = true;
        }
      } else {
        int idx = 0;
        memset(b, 0, sizeof(b));
        for (int i = 0; i < m; i++)
          if (a[i] != 0) b[idx++] = a[i];
        memcpy(a, b, sizeof(a));
      }
    }
  }
}
