← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	firstLine := scanner.Text()
	params := strings.Fields(firstLine)
	t, _ := strconv.Atoi(params[0])
	m, _ := strconv.Atoi(params[1])

	mem := make([]int, m)
	nextID := 1

	for i := 0; i < t; i++ {
		scanner.Scan()
		line := scanner.Text()
		fields := strings.Fields(line)
		op := fields[0]

		if op == "alloc" {
			n, _ := strconv.Atoi(fields[1])
			found := false
			var start int
			for s := 0; s <= m-n; s++ {
				ok := true
				for j := 0; j < n; j++ {
					if mem[s+j] != 0 {
						ok = false
						break
					}
				}
				if ok {
					found = true
					start = s
					break
				}
			}
			if !found {
				fmt.Println("NULL")
			} else {
				for j := 0; j < n; j++ {
					mem[start+j] = nextID
				}
				fmt.Println(nextID)
				nextID++
			}
		} else if op == "erase" {
			x, _ := strconv.Atoi(fields[1])
			exists := false
			for j := 0; j < m; j++ {
				if mem[j] == x {
					exists = true
					break
				}
			}
			if !exists {
				fmt.Println("ILLEGAL_ERASE_ARGUMENT")
			} else {
				for j := 0; j < m; j++ {
					if mem[j] == x {
						mem[j] = 0
					}
				}
			}
		} else if op == "defragment" {
			newmem := make([]int, m)
			p := 0
			for j := 0; j < m; j++ {
				if mem[j] != 0 {
					newmem[p] = mem[j]
					p++
				}
			}
			mem = newmem
		}
	}
}
```