3 1
erase -1
erase 0
erase -2147483648
 26 25
defragment
erase 1
erase -1560200883
alloc 44
defragment
alloc 75
alloc 22
defragment
erase 4
defragment
alloc 57
alloc 53
erase 4
erase -1639632026
erase -2121605039
erase 3
alloc 51
alloc 65
defragment
erase 2
erase 4
alloc 52
erase 3
defragment
erase -1842529282
erase 3
 12 40
erase 1
alloc 21
alloc 5
alloc 7
defragment
defragment
erase 2
alloc 83
erase 4
defragment
alloc 59
defragment
 44 46
alloc 28
alloc 36
defragment
erase -937404236
alloc 71
defragment
alloc 81
alloc 51
erase 3
defragment
alloc 48
erase 1
defragment
alloc 36
defragment
defragment
erase 1
defragment
defragment
erase -1173350787
alloc 94
erase 5
defragment
erase 9
alloc 98
erase 7
defragment
erase 5
erase 1
defragment
erase 2
defragment
erase 4
defragment
erase 9
alloc 8
defragment
erase 9
defragment
defragment
defragment
erase 1
alloc 70
erase 9
 7 6
alloc 1
alloc 2
alloc 3
erase 1
defragment
erase 3
alloc 4
 47 43
erase 1
alloc 95
alloc 53
erase 2
defragment
alloc 100
erase 4
erase 2
erase -849472053
defragment
erase -638355221
alloc 90
erase 3
erase 2
defragment
alloc 17
erase 5
defragment
erase 6
defragment
erase 3
defragment
defragment
alloc 99
alloc 69
alloc 80
erase 9
erase 5
defragment
erase 7
defragment
alloc 93
defragment
defragment
alloc 25
defragment
alloc 14
erase 8
erase 4
defragment
defragment
alloc 96
erase 9
alloc 63
erase 8
defragment
erase 10
 8 50
alloc 51
defragment
alloc 100
defragment
erase 1
alloc 50
defragment
alloc 50
 6 1
defragment
alloc 10
alloc 1
erase -1
erase 1
erase 1
 26 25
alloc 25
erase 1
alloc 24
erase 2
alloc 23
erase 3
alloc 24
erase 4
alloc 24
erase 5
alloc 21
erase 6
alloc 24
erase 7
alloc 25
erase 8
alloc 25
erase 9
alloc 24
erase 10
alloc 25
erase 11
alloc 25
erase 12
alloc 25
erase 13
 10 10
alloc 10
erase -1
erase 1
alloc 5
erase -1
alloc 5
erase 0
alloc 5
erase 0
alloc 5
 37 74
alloc 11
defragment
erase 1
defragment
erase 2
defragment
alloc 90
erase 3
erase 2
erase 3
erase 1
erase 1
alloc 38
alloc 19
erase 1
erase 3
defragment
alloc 93
erase 5
erase 4
alloc 66
alloc 71
erase 5
defragment
defragment
defragment
defragment
erase 7
alloc 47
erase -95616683
erase 2
alloc 28
alloc 32
erase 11
alloc 50
defragment
defragment
 19 46
alloc 21
erase 2
erase 1
defragment
alloc 4
defragment
defragment
alloc 40
erase 1
defragment
defragment
alloc 68
erase -388966015
alloc 85
alloc 53
erase 4
defragment
alloc 49
alloc 88
 12 10
alloc 6
alloc 2
erase 1
alloc 4
alloc 2
erase 3
alloc 2
alloc 3
alloc 1
alloc 1
alloc 1
alloc 1
 16 10
alloc 10
defragment
defragment
defragment
alloc 10
erase 1
erase 2
alloc 6
defragment
defragment
alloc 4
defragment
defragment
erase 2
defragment
alloc 6
 14 100
alloc 99
alloc 1
alloc 1
erase 2
alloc 1
erase 4
erase 1
alloc 100
alloc 1
alloc 99
defragment
erase 4
alloc 100
alloc 99
 22 9
alloc 9
erase 1
alloc 9
erase 2
alloc 9
erase 3
alloc 9
erase 4
alloc 9
erase 5
alloc 9
erase 6
alloc 9
erase 7
alloc 9
erase 8
alloc 9
erase 9
alloc 9
erase 10
alloc 9
erase 11
 42 98
defragment
defragment
defragment
defragment
defragment
alloc 5
alloc 66
defragment
erase 3
alloc 53
defragment
erase 4
erase 2
alloc 70
erase 3
defragment
defragment
erase 2
erase 3
erase -1327931832
alloc 93
alloc 64
erase 7
erase 6
erase 3
alloc 61
alloc 12
alloc 65
erase 2
alloc 46
erase 11
erase 9
erase 9
erase 6
alloc 2
alloc 78
defragment
erase 13
erase 6
erase 10
alloc 53
alloc 46
 16 10
alloc 10
defragment
defragment
defragment
alloc 10
erase 1
erase 2
alloc 6
defragment
defragment
alloc 4
defragment
defragment
erase 3
defragment
alloc 6
 38 18
alloc 72
erase 2
alloc 50
defragment
erase 3
defragment
alloc 43
alloc 41
defragment
defragment
alloc 26
alloc 46
alloc 16
alloc 15
defragment
defragment
alloc 95
erase 7
erase 7
erase 5
erase 2
erase 9
erase 7
alloc 43
defragment
erase 7
defragment
alloc 48
alloc 77
erase 10
erase 11
alloc 16
alloc 84
erase 1
defragment
alloc 86
defragment
erase 13
 16 49
erase -751005193
defragment
alloc 37
alloc 82
erase 3
erase 1
alloc 80
alloc 51
defragment
alloc 74
erase 1
alloc 91
defragment
defragment
alloc 98
defragment
 22 9
erase 1
alloc 6
alloc 65
erase 1
alloc 87
erase -1638927047
alloc 5
erase 2
alloc 70
defragment
alloc 20
alloc 48
erase -69401977
alloc 20
defragment
erase 7
defragment
erase 9
erase 7
erase 4
defragment
alloc 66
 7 100
alloc 100
erase 2147483647
erase 1
alloc 50
alloc 50
erase 3
erase -2147483648

ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
 ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
1
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
 ILLEGAL_ERASE_ARGUMENT
1
2
3
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
 1
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
2
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
3
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
 1
2
3
4
 ILLEGAL_ERASE_ARGUMENT
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
1
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
2
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
 NULL
NULL
ILLEGAL_ERASE_ARGUMENT
1
NULL
 NULL
1
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
 1
2
3
4
5
6
7
8
9
10
11
12
13
 1
ILLEGAL_ERASE_ARGUMENT
2
ILLEGAL_ERASE_ARGUMENT
3
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
 1
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
2
3
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
4
5
ILLEGAL_ERASE_ARGUMENT
NULL
 1
ILLEGAL_ERASE_ARGUMENT
2
3
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
 1
2
3
4
5
NULL
6
7
8
9
 1
NULL
ILLEGAL_ERASE_ARGUMENT
2
3
4
 1
2
NULL
3
ILLEGAL_ERASE_ARGUMENT
NULL
4
NULL
NULL
NULL
 1
2
3
4
5
6
7
8
9
10
11
 1
2
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
3
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
4
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
 1
NULL
ILLEGAL_ERASE_ARGUMENT
2
3
NULL
 NULL
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
NULL
NULL
1
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
 ILLEGAL_ERASE_ARGUMENT
1
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
NULL
 ILLEGAL_ERASE_ARGUMENT
1
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
2
NULL
NULL
NULL
ILLEGAL_ERASE_ARGUMENT
NULL
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
ILLEGAL_ERASE_ARGUMENT
NULL
 1
ILLEGAL_ERASE_ARGUMENT
2
3
ILLEGAL_ERASE_ARGUMENT

import java.util.ArrayList;
import java.util.Scanner;

public class B_MemoryManager 
{

	static int lastId = 0;
	public static void main(String[] args) 
	{
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		int m = in.nextInt();
		
		Block b = new Block(0, m, 0, "free");

		ArrayList<Block> blocks = new ArrayList<>();
		blocks.add(b);
		
		while(t > 0)
		{
			String command = in.next();
			if(command.equals("alloc"))
			{
				int size = in.nextInt();
				int id = allocate (blocks, size);
				if(id == -1)
					System.out.println("NULL");
				else
					System.out.println(lastId);
			}
			else if(command.equals("erase"))
			{
				int id = in.nextInt();
				int result = erase(blocks, id);
				if(result == -1)
					System.out.println("ILLEGAL_ERASE_ARGUMENT");
			}
			else
			{
				defragment(blocks);
			}
			
			t--;
		}
	}
	
	private static void defragment(ArrayList<Block> blocks)
	{
		//System.out.println("before defragmentation");
		//System.out.println(blocks);
		ArrayList <Block> notFreeBlocks = new ArrayList<>();
		int freeBlocksSize = 0;
		int newStartingIndex = 0;
		for(int i = 0; i < blocks.size(); i++)
		{
			Block block = blocks.get(i);
			if(block.getState().equals("notFree"))
			{
				block.setStartingIndex(newStartingIndex);
				notFreeBlocks.add(block);
				newStartingIndex = newStartingIndex + block.getSize();
			}
			else
			{
				freeBlocksSize = freeBlocksSize + block.getSize();
			}
		}	
		
		blocks.clear();
		for(int i = 0; i < notFreeBlocks.size(); i++)
		{
			blocks.add(notFreeBlocks.get(i));
		}		
		if(freeBlocksSize > 0)
		{
			Block b = new Block(-1, freeBlocksSize, newStartingIndex, "free");
			blocks.add(b);
		}
		//System.out.println("after defragmentation");
		//System.out.println(blocks);
		
	}

	//returns 1 in case of successful erase or -1 in case of failed erase
	private static int erase(ArrayList<Block> blocks, int id)
	{
		//System.out.println("before erase");
		//System.out.println(blocks);
		for(int i = 0; i < blocks.size(); i++)
		{
			Block b = blocks.get(i);
			if(b.getIdentifier() == id)
			{
				b.setState("free");
				b.setIdentifier(-1);
				mergeFreeBlocks(i, blocks);	
				
				//System.out.println("after erase");
				//System.out.println(blocks);
				return 1;
			}
		}
		return -1;
	}

	private static void mergeFreeBlocks(int i, ArrayList<Block> blocks)
	{
		int size = blocks.size();
		Block b = blocks.get(i);
		boolean v1 = valid(i - 1, size);
		boolean v2 = valid(i + 1, size);
		if(v1 && v2) 
		{
			Block beforeB = blocks.get(i - 1);
			Block afterB = blocks.get((i + 1));
			if(beforeB.getState().equals("free") && afterB.getState().equals("free"))
			{
				int newSize = b.getSize() + beforeB.getSize() + afterB.getSize();
				beforeB.setSize(newSize);
				blocks.remove(b);
				blocks.remove(afterB);
				
			}
			else if(beforeB.getState().equals("notFree") && afterB.getState().equals("free"))
			{
				int newSize = b.getSize() + afterB.getSize();
				b.setSize(newSize);
				blocks.remove(afterB);
			}
			else if(beforeB.getState().equals("free") && afterB.getState().equals("notFree"))
			{
				int newSize = b.getSize() + beforeB.getSize();
				beforeB.setSize(newSize);
				blocks.remove(b);	
			}
		}
		else if(!v1 && v2)
		{
			Block afterB = blocks.get((i + 1));
			if(afterB.getState().equals("free"))
			{
				int newSize = b.getSize() + afterB.getSize();
				b.setSize(newSize);
				blocks.remove(afterB);
			}
		}
		else if(v1 && !v2)
		{
			Block beforeB = blocks.get(i - 1);
			if(beforeB.getState().equals("free"))
			{
				int newSize = b.getSize() + beforeB.getSize();
				beforeB.setSize(newSize);
				blocks.remove(b);						
			}
		}		
	}

	private static boolean valid(int i, int size) 
	{
		if(i >= 0 && i < size)
			return true;
		
		return false;
	}

	private static int allocate(ArrayList<Block> blocks, int size) 
	{
		//System.out.println("before allocation");
		//System.out.println(blocks);
		for(int i = 0; i < blocks.size(); i++)
		{
			Block b = blocks.get(i);
			if(b.getState().equals("free"))
			{ 
				if(b.getSize() == size)
				{
					lastId = lastId + 1;
					b.setIdentifier(lastId);
					b.setState("notFree");
					return lastId;
				}
				else if(b.getSize() > size)
				{
					//create a new free block
					int size2 = b.getSize() - size;
					int startingIndex2 = b.getStartingIndex() + size;
					Block b2 = new Block(-1, size2, startingIndex2, "free");
					blocks.add(b2);
					
					//adjust the free b block to be the new allocated block
					lastId = lastId + 1;
					b.setIdentifier(lastId);
					b.setState("notFree");
					b.setSize(size);
										
					//System.out.println("after allocation");
					//System.out.println(blocks);
					return lastId;
				}
			}
		}
		return -1;
	}

	
	 
	public static class Block
	{
		private int identifier;
		private int size;
		private int startingIndex;
		private String state;
		
		public Block(int identifier, int size, int startingIndex, String state) 
		{
			this.identifier = identifier;
			this.size = size;
			this.startingIndex = startingIndex;
			this.state = state;
		}	
		@Override
		public String toString() {
			return "Block [identifier=" + identifier + ", size=" + size + ", startingIndex=" + startingIndex + ", state="
					+ state + "]";
		}
		public int getIdentifier() {
			return identifier;
		}
		public void setIdentifier(int identifier) {
			this.identifier = identifier;
		}
		public int getSize() {
			return size;
		}
		public void setSize(int size) {
			this.size = size;
		}
		public int getStartingIndex() {
			return startingIndex;
		}
		public void setStartingIndex(int startingIndex) {
			this.startingIndex = startingIndex;
		}
		public String getState() {
			return state;
		}
		public void setState(String state) {
			this.state = state;
		}
	}
}
