assistant: t, m = map(int, input().split())
alocuente = [0] * m
ind = 1
for i in range(t):
    op = input().split()
    if op[0] == 'alloc':
        pos = 0
        for j in range(m):
            if alocuente[j] == 0:
                pos += 1
                if pos == int(op[1]):
                    alocuente[j - int(op[1]) + 1: j + 1] = [ind] * int(op[1])
                    print(ind)
                    ind += 1
                    break
            else:
                pos = 0
        else:
            print("NULL")
    if op[0] == 'erase':
        pos = 0
        if int(op[1]) not in alocuente or int(op[1]) == 0:
            print('ILLEGAL_ERASE_ARGUMENT')
        else:
            for j in range(m):
                if int(op[1]) > 0 and alocuente[j] == int(op[1]):
                    alocuente[j] = 0
    if op[0] == "defragment":
        cnt = 0
        cnt = alocuente.count(0)
        alocuente = [j for j in alocuente if j != 0]
        for j in range(cnt):
            alocuente.append(0)


user: import java.util.*;

public class codeforces_7_B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int t = s.nextInt();
        int m = s.nextInt();
        int[] memory = new int[m];
        int allocIdx = 0;
        for (int j = 0; j < t; j++) {
            switch (s.next()) {
                case "alloc":
                    int n = s.nextInt();
                    int len = 0;
                    boolean canAlloc = false;
                    for (int i = 0; i < m; i++) {
                        if (memory[i] == 0) len++;
                        else len = 0;
                        if (len == n) {
                            canAlloc = true;
                            len = i - n + 1;
                            break;
                        }
                    }
                    if (canAlloc) {
                        allocIdx++;
                        for (int i = len; i < len + n; i++) memory[i] = allocIdx;
                        System.out.println(allocIdx);
                    } else System.out.println("NULL");
                    break;
                case "erase":
                    int x = s.nextInt();
                    if (x <= 0) {
                        System.out.println("ILLEGAL_ERASE_ARGUMENT");
                        break;
                    }
                    boolean hasErased = false;
                    for (int i = 0; i < m; i++) {
                        if (memory[i] == x) {
                            memory[i] = 0;
                            hasErased = true;
                        }
                    }
                    if (!hasErased) System.out.println("ILLEGAL_ERASE_ARGUMENT");
                    break;
                case "defragment":
                    int d = 0;
                    for (int i = 0; i < m; i++) {
                        if (memory[i] == 0) d++;
                        else memory[i - d] = memory[i];
                    }
                    for (int i = m - d; i < m; i++) memory[i] = 0;
                    break;
                default:
                    System.out.println("h");
                    break;
            }
        }
        s.close();
    }
}