#include<bits/stdc++.h>
using namespace std;
#define in inline
#define ll long long
const int N=210;
in int read()
{
	int w=0,r=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')r=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		w=(w<<1)+(w<<3)+(ch^48);
		ch=getchar();
	}
	return w*r;
}

int T,m,id;

struct node
{
	int l,r,name,siz;
}nd[N];
bool mark[N],flag[N],vis[N];

void part1()
{
	for(int i=1;i<=m;i++)
	{
		vis[i]=mark[i];
	}
	int n=read();
	int l=0,r=0,cnt=0;
	id++;
	for(int i=1;i<=m;i++)
	{
		if(vis[i]==1)
		{
			l=0;
			r=0;
			cnt=0;
		}
		if(vis[i]==0)
		{
			if(l==0)
			{
				l=i;
				r=i;
				cnt=1;
//				vis[i]=1;
			}
			else
			{
				cnt++;
				r++;
//				vis[i]=1;
			}

		}
		if(cnt==n)
		{
			nd[id].l=l;
			nd[id].r=r;
			nd[id].name=id;
			nd[id].siz=n;
			cout<<id<<endl;
			for(int j=l;j<=r;j++)
			{
				mark[j]=1;
			}
			break;
		}
	}
	if(nd[id].l==0&&nd[id].r==0)
	{
		puts("NULL");
//		flag[id]=1;
		id--;
	}
}

void part2()
{
	int n=read();
	if(flag[n]==1||id<n||n<1)
	{
		puts("ILLEGAL_ERASE_ARGUMENT");
		return ;
	}
	flag[n]=1;
	for(int i=nd[n].l;i<=nd[n].r;i++)
	{
		mark[i]=0;
	}
}

void part3()
{
	int last=1,num=0;
	for(int i=1;i<=id;i++)
	{
		if(flag[i]==1)continue;
		nd[i].l=last;
		last=nd[i].r+1;
		nd[i].r=nd[i].l+nd[i].siz-1;
		num+=nd[i].siz;
	}
	for(int i=1;i<=num;i++)
	{
		mark[i]=1;
	}
	for(int i=num+1;i<=m;i++)
	{
		mark[i]=0;
	}
}

int main()
{
//	freopen("1.in","r",stdin);
	T=read();
	m=read();
//	mark[0]=1;
//	mark[m+1]=1;
	for(int k=1;k<=T;k++)
	{
		string str;
		cin>>str;
		if(str=="alloc")
		{
			part1();
		}
		if(str=="erase")
		{
			part2();
		}
		if(str=="defragment")
		{
			part3();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in inline
#define ll long long
const int N=210;
in int read()
{
	int w=0,r=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')r=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		w=(w<<1)+(w<<3)+(ch^48);
		ch=getchar();
	}
	return w*r;
}

int T,m,id;

struct node
{
	int l,r,name,siz;
}nd[N];
bool mark[N],flag[N],vis[N];

void part1()
{
	for(int i=1;i<=m;i++)
	{
		vis[i]=mark[i];
	}
	int n=read();
	int l=0,r=0,cnt=0;
	id++;
	for(int i=1;i<=m;i++)
	{
		if(vis[i]==1)
		{
			l=0;
			r=0;
			cnt=0;
		}
		if(vis[i]==0)
		{
			if(l==0)
			{
				l=i;
				r=i;
				cnt=1;
//				vis[i]=1;
			}
			else
			{
				cnt++;
				r++;
//				vis[i]=1;
			}

		}
		if(cnt==n)
		{
			nd[id].l=l;
			nd[id].r=r;
			nd[id].name=id;
			nd[id].siz=n;
			cout<<id<<endl;
			for(int j=l;j<=r;j++)
			{
				mark[j]=1;
			}
			break;
		}
	}
	if(nd[id].l==0&&nd[id].r==0)
	{
		puts("NULL");
		flag[id]=1;
		id--;
	}
}

void part2()
{
	int n=read();
	if(flag[n]==1)
	{
		puts("ILLEGAL_ERASE_ARGUMENT");
		return ;
	}
	flag[n]=1;
	for(int i=nd[n].l;i<=nd[n].r;i++)
	{
		mark[i]=0;
	}
}

void part3()
{
	int last=1,num=0;
	for(int i=1;i<=id;i++)
	{
		if(flag[i]==1)continue;
		nd[i].l=last;
		last=nd[i].r+1;
		nd[i].r=nd[i].l+nd[i].siz-1;
		num+=nd[i].siz;
	}
	for(int i=1;i<=num;i++)
	{
		mark[i]=1;
	}
	for(int i=num+1;i<=m;i++)
	{
		mark[i]=0;
	}
}

int main()
{
//	freopen("1.in","r",stdin);
	T=read();
	m=read();
	mark[0]=1;
	mark[m+1]=1;
	for(int k=1;k<=T;k++)
	{
		string str;
		cin>>str;
		if(str=="alloc")
		{
			part1();
		}
		if(str=="erase")
		{
			part2();
		}
		if(str=="defragment")
		{
			part3();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in inline
#define ll long long
const int N=2100;
in int read()
{
	int w=0,r=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')r=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		w=(w<<1)+(w<<3)+(ch^48);
		ch=getchar();
	}
	return w*r;
}

int T,m,id;

struct node
{
	int l,r,name,siz;
}nd[N],nv[N];
bool mark[N],flag[N],vis[N];

void part1()
{
	for(int i=1;i<=m;i++)
	{
		vis[i]=mark[i];
	}
	int n=read();
	int l=0,r=0,cnt=0;
	id++;
	for(int i=1;i<=m;i++)
	{
		if(vis[i]==1)
		{
			l=0;
			r=0;
			cnt=0;
		}
		if(vis[i]==0)
		{
			if(l==0)
			{
				l=i;
				r=i;
				cnt=1;
//				vis[i]=1;
			}
			else
			{
				cnt++;
				r++;
//				vis[i]=1;
			}

		}
		if(cnt==n)
		{
			nd[id].l=l;
			nd[id].r=r;
			nd[id].name=id;
			nd[id].siz=n;
			cout<<id<<endl;
//			flag[id]=1;
			for(int j=l;j<=r;j++)
			{
				mark[j]=1;
			}
			break;
		}
	}
	if(nd[id].l==0&&nd[id].r==0)
	{
		puts("NULL");
//		flag[id]=1;
		id--;
	}
}

void part2()
{
	int n=read();
//	if(n>m)
//	{
//
//	}
	if(id<n||n<1||flag[n]==1)
	{
		puts("ILLEGAL_ERASE_ARGUMENT");
		return ;
	}
	flag[n]=1;
	for(int i=nd[n].l;i<=nd[n].r;i++)
	{
		mark[i]=0;
	}
}

in bool cmp(node a,node b)
{
	return a.l<b.l;
}

void part3()
{
	for(int i=1;i<=id;i++)
	{
		nv[i]=nd[i];
	}
	sort(nv+1,nv+1+id,cmp);
	int last=1,num=0;
	for(int i=1;i<=id;i++)
	{
		int x=nv[i].name;
//		cout<<x<<endl;
		if(flag[x]==1)continue;
		nd[x].l=last;
		last=nd[x].r+1;
		nd[x].r=nd[x].l+nd[x].siz-1;
		num+=nd[x].siz;
	}
	for(int i=1;i<=num;i++)
	{
		mark[i]=1;
	}
	for(int i=num+1;i<=m;i++)
	{
		mark[i]=0;
	}
}

int main()
{
//	freopen("1.in","r",stdin);
	T=read();
	m=read();
//	mark[0]=1;
//	mark[m+1]=1;
	for(int k=1;k<=T;k++)
	{
		string str;
		cin>>str;
		if(str=="alloc")
		{
			part1();
		}
		if(str=="erase")
		{
			part2();
		}
		if(str=="defragment")
		{
			part3();
		}
//		for(int i=1;i<=m;i++)
//		{
//			cout<<mark[i]<<" ";
//		}
//		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in inline
#define ll long long
const int N=210;
in int read()
{
	int w=0,r=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')r=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		w=(w<<1)+(w<<3)+(ch^48);
		ch=getchar();
	}
	return w*r;
}

int T,m,id;

struct node
{
	int l,r,name,siz;
}nd[N];
bool mark[N],flag[N];

void part1()
{
	int n=read();
	int l=0,r=0,cnt=0;
	id++;
	for(int i=1;i<=m;i++)
	{
		if(mark[i]==1)
		{
			l=0;
			r=0;
			cnt=0;
		}
		if(mark[i]==0)
		{
			if(l==0)
			{
				l=i;
				r=i;
				cnt=1;
				mark[i]=1;
			}
			else
			{
				cnt++;
				r++;
				mark[i]=1;
			}

		}
		if(cnt==n)
		{
			nd[id].l=l;
			nd[id].r=r;
			nd[id].name=id;
			nd[id].siz=n;
			cout<<id<<endl;
			break;
		}
	}
	if(nd[id].l==0&&nd[id].r==0)
	{
		puts("NULL");
		flag[id]=1;
		id--;
	}
}

void part2()
{
	int n=read();
	if(flag[n]==1)
	{
		puts("ILLEGAL_ERASE_ARGUMENT");
		return ;
	}
	flag[n]=1;
	for(int i=nd[n].l;i<=nd[n].r;i++)
	{
		mark[i]=0;
	}
}

void part3()
{
	int last=1,num=0;
	for(int i=1;i<=id;i++)
	{
		if(flag[i]==1)continue;
		nd[i].l=last;
		last=nd[i].r+1;
		nd[i].r=nd[i].l+nd[i].siz-1;
		num+=nd[i].siz;
	}
	for(int i=1;i<=num;i++)
	{
		mark[i]=1;
	}
	for(int i=num+1;i<=m;i++)
	{
		mark[i]=0;
	}
}

int main()
{
//	freopen("1.in","r",stdin);
	T=read();
	m=read();
	mark[0]=1;
	mark[m+1]=1;
	for(int k=1;k<=T;k++)
	{
		string str;
		cin>>str;
		if(str=="alloc")
		{
			part1();
		}
		if(str=="erase")
		{
			part2();
		}
		if(str=="defragment")
		{
			part3();
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define sf(x) scanf("%d", &x);
#define sf2(x, y) scanf("%d %d", &x, &y);
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define pi 3.1415926536
int main()
{
    int t,m,x,p = 1;
    cin >> t >> m;
    vector<int> a(1000,0);
    while(t--)
    {
        string s;
        cin >> s;
        if(s == "alloc"||s == "erase")cin >> x;
        if(s == "alloc")
        {
            bool d = 0;
            for(int i = 1;i <= m;i++)
            {
                if(i + x-1 > m){break;}
                bool k = 1;
                for(int j = i;j <= i+x-1;j++)
                {
                    if(a[j] > 0){k = 0;break;}
                }
                if(k)
                {
                    d = 1;
                    for(int j = i;j <= i+x-1;j++)a[j] = p;
                    break;
                }
            }
            if(d)
            {
                cout << p << endl;
                p++;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if(s == "erase")
        {
            if(x < 1){cout << "ILLEGAL_ERASE_ARGUMENT\n";continue;}
            bool o = 0;
            for(int i = 1;i <= m;i++)
            {
                if(a[i] == x){a[i] = 0;o = 1;}
            }
            if(!o){cout << "ILLEGAL_ERASE_ARGUMENT\n";}
        }
        else
        {
            int l = 1;
            for(int i = 1;i <= m;i++)
            {
                if(a[i] > 0)
                {
                    a[l] = a[i];
                    a[i] = 0;
                    l++;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define sf(x) scanf("%d", &x);
#define sf2(x, y) scanf("%d %d", &x, &y);
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define pi 3.1415926536
int main()
{
    int t,m,x,p = 1;
    cin >> t >> m;
    vector<int> a(m+5,0),me(1000,0);
    while(t--)
    {
        string s;
        cin >> s;
        if(s == "alloc"||s == "erase")cin >> x;
        if(s == "alloc")
        {
            bool d = 0;
            for(int i = 1;i <= m;i++)
            {
                if(i + x-1 > m){break;}
                bool k = 1;
                for(int j = i;j <= i+x-1;j++)
                {
                    if(a[j] > 0){k = 0;break;}
                }
                if(k)
                {
                    d = 1;
                    for(int j = i;j <= i+x-1;j++)a[j] = p;
                    break;
                }
            }
            if(d)
            {
                cout << p << endl;
                me[p] = 1;
                p++;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if(s == "erase")
        {
            if(me[x] == 0){cout << "ILLEGAL_ERASE_ARGUMENT" << endl;}
            else
            {
                for(int i = 1;i <= m;i++)
                {
                    if(a[i] == x)a[i] = 0;
                }
            }
        }
        else
        {
            int l = 1;
            for(int i = 1;i <= m;i++)
            {
                if(a[i] > 0)
                {
                    a[l] = a[i];
                    a[i] = 0;
                    l++;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define sf(x) scanf("%d", &x);
#define sf2(x, y) scanf("%d %d", &x, &y);
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define pi 3.1415926536
int main()
{
    int t,m,x,p = 1;
    cin >> t >> m;
    vector<int> a(m+5,0),me(1000,0);
    while(t--)
    {
        string s;
        cin >> s;
        if(s == "alloc"||s == "erase")cin >> x;
        if(s == "alloc")
        {
            bool d = 0;
            for(int i = 1;i <= m;i++)
            {
                if(i + x-1 > m){break;}
                bool k = 1;
                for(int j = i;j <= i+x-1;j++)
                {
                    if(a[j] > 0){k = 0;break;}
                }
                if(k)
                {
                    d = 1;
                    for(int j = i;j <= i+x-1;j++)a[j] = p;
                    break;
                }
            }
            if(d)
            {
                cout << p << endl;
                me[p] = 1;
                p++;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if(s == "erase")
        {
            if(me[x] == 0||x < 1){cout << "ILLEGAL_ERASE_ARGUMENT" << endl;}
            else
            {
                me[x] = 0;
                for(int i = 1;i <= m;i++)
                {
                    if(a[i] == x)a[i] = 0;
                }
            }
        }
        else
        {
            int l = 1;
            for(int i = 1;i <= m;i++)
            {
                if(a[i] > 0)
                {
                    a[l] = a[i];
                    a[i] = 0;
                    l++;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define sf(x) scanf("%d", &x);
#define sf2(x, y) scanf("%d %d", &x, &y);
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define pi 3.1415926536
int main()
{
    int t,m,x,p = 1;
    cin >> t >> m;
    vector<int> a(1000,0),me(1000,0);
    while(t--)
    {
        string s;
        cin >> s;
        if(s == "alloc"||s == "erase")cin >> x;
        if(s == "alloc")
        {
            bool d = 0;
            for(int i = 1;i <= m;i++)
            {
                if(i + x-1 > m){break;}
                bool k = 1;
                for(int j = i;j <= i+x-1;j++)
                {
                    if(a[j] > 0){k = 0;break;}
                }
                if(k)
                {
                    d = 1;
                    for(int j = i;j <= i+x-1;j++)a[j] = p;
                    break;
                }
            }
            if(d)
            {
                cout << p << endl;
                me[p] = 1;
                p++;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if(s == "erase")
        {
            if(x < 1){cout << "ILLEGAL_ERASE_ARGUMENT" << endl;}
            else if(me[x] == 0){cout << "ILLEGAL_ERASE_ARGUMENT" << endl;}
            else
            {
                me[x] = 0;
                for(int i = 1;i <= m;i++)
                {
                    if(a[i] == x)a[i] = 0;
                }
            }
        }
        else
        {
            int l = 1;
            for(int i = 1;i <= m;i++)
            {
                if(a[i] > 0)
                {
                    a[l] = a[i];
                    a[i] = 0;
                    l++;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define sf(x) scanf("%d", &x);
#define sf2(x, y) scanf("%d %d", &x, &y);
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define pi 3.1415926536
int main()
{
    int t,m,x,p = 1;
    cin >> t >> m;
    vector<int> a(1000,0);
    while(t--)
    {
        string s;
        cin >> s;
        if(s == "alloc")
        {
            cin >> x;
            bool d = 0;
            for(int i = 1;i + (x-1) <= m;i++)
            {
                bool k = 1;
                for(int j = i;j <= i+x-1;j++)
                {
                    if(a[j] > 0){k = 0;break;}
                }
                if(k)
                {
                    d = 1;
                    for(int j = i;j <= i+x-1;j++)a[j] = p;
                    break;
                }
            }
            if(d)
            {
                cout << p << endl;
                p++;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if(s == "erase")
        {
            cin >> x;
            if(x < 1){cout << "ILLEGAL_ERASE_ARGUMENT\n";continue;}
            bool o = 0;
            for(int i = 1;i <= m;i++)
            {
                if(a[i] == x){a[i] = 0;o = 1;}
            }
            if(!o){cout << "ILLEGAL_ERASE_ARGUMENT\n";}
        }
        else
        {
            int l = -1;
            for(int i = 1;i <= m;i++)
            {
                if(a[i] == 0){l = i;break;}
            }
            if(l == -1)continue;
            for(int i = l;i <= m;i++)
            {
                if(a[i] > 0)
                {
                    a[l] = a[i];
                    a[i] = 0;
                    l++;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define sf(x) scanf("%d", &x);
#define sf2(x, y) scanf("%d %d", &x, &y);
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define pi 3.1415926536
int main()
{
    int t,m,x,p = 1;
    cin >> t >> m;
    vector<int> a(m+5,0),me(1000,0);
    while(t--)
    {
        string s;
        cin >> s;
        if(s == "alloc"||s == "erase")cin >> x;
        if(s == "alloc")
        {
            bool d = 0;
            for(int i = 1;i <= m;i++)
            {
                if(i + x-1 > m){break;}
                bool k = 1;
                for(int j = i;j <= i+x-1;j++)
                {
                    if(a[j] > 0){k = 0;break;}
                }
                if(k)
                {
                    d = 1;
                    for(int j = i;j <= i+x-1;j++)a[j] = p;
                    break;
                }
            }
            if(d)
            {
                cout << p << endl;
                me[p] = 1;
                p++;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if(s == "erase")
        {
            if(me[x] == 0){cout << "ILLEGAL_ERASE_ARGUMENT" << endl;}
            else
            {
                me[x] = 0;
                for(int i = 1;i <= m;i++)
                {
                    if(a[i] == x)a[i] = 0;
                }
            }
        }
        else
        {
            int l = 1;
            for(int i = 1;i <= m;i++)
            {
                if(a[i] > 0)
                {
                    a[l] = a[i];
                    a[i] = 0;
                    l++;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define sf(x) scanf("%d", &x);
#define sf2(x, y) scanf("%d %d", &x, &y);
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define pi 3.1415926536
int main()
{
    int t,m,x,p = 1;
    cin >> t >> m;
    vector<int> a(1000,0);
    while(t--)
    {
        string s;
        cin >> s;
        if(s == "alloc"||s == "erase")cin >> x;
        if(s == "alloc")
        {
            bool d = 0;
            for(int i = 1;i <= m;i++)
            {
                if(i + x-1 > m){break;}
                bool k = 1;
                for(int j = i;j <= i+x-1;j++)
                {
                    if(a[j] > 0){k = 0;break;}
                }
                if(k)
                {
                    d = 1;
                    for(int j = i;j <= i+x-1;j++)a[j] = p;
                    break;
                }
            }
            if(d)
            {
                cout << p << endl;
                p++;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if(s == "erase")
        {
            bool o = 0;
            for(int i = 1;i <= m;i++)
            {
                if(a[i] == x){a[i] = 0;o = 1;}
            }
            if(!o){cout << "ILLEGAL_ERASE_ARGUMENT\n";}
        }
        else
        {
            int l = 1;
            for(int i = 1;i <= m;i++)
            {
                if(a[i] > 0)
                {
                    a[l] = a[i];
                    a[i] = 0;
                    l++;
                }
            }
        }
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <ctime>
#include <iostream>
#include <cmath>
#include <stack>
#include <sstream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cassert>

const long double PI(acosl(-1.0));
long double eps = 1e-9;

#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define inf (int)(1e9+7)
#define infll (ll)(1e18+3)
#define sz(x) ((int)x.size())
#define bits(x) __builtin_popcount(x)
#define bitsl(x) __builtin_popcountll(x)
#define rep(i, a, b) for (int (i) = (a); i <= (b); ++(i))
#define forn(i, n) rep(i, 0, n-1)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector < ll > vll;
typedef vector<int> vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector<vi> vii;
typedef int huint;

const int N = 2 * 1e5;

int t, m;
int a[1000];
pii start[1000];
int k;

int find(int ln)
{
    for (int i(1); i <= m; i++)
    {
        int cnt = 0;
        for (int j(i); j < i + ln; j++)
        {
            if (j > m) break;
            if (a[j] != 0) break;
            cnt++;
        }
        if (cnt == ln)
        {
            start[k] = mp(i,ln);
            for (int j(i); j < i + ln; j++)
                a[j] = k;
            k++;
            return k - 1;
        }
    }
    return -1;
}

int del(int ind)
{
    if (start[ind].F == -1) return -1;
    for (int i(start[ind].F); i < start[ind].F + start[ind].S; i++)
    {
        a[i] = 0;
    }
    start[ind].F = -1;
    return 0;
}
void turnLeft()
{
    vector<int> fl(m+2, 0);
    int cnt = 0;
    for (int i(1); i <= m; i++)
    {
        if (a[i] == 0) cnt++;
        else
        {
            if (fl[a[i]] != 0) continue;
            fl[a[i]] = 1;
            start[a[i]].F -= cnt;
        }
    }
    int stp = 0;
    for (int i(1); i < k; i++)
    {
        if (start[i].F == -1) continue;

        for (int j(start[i].F); j < start[i].F + start[i].S; j++)
        {
            a[j] = i;
            stp = j;
        }
    }
    stp++;
    for (int i(stp); i <= m; i++)
        a[i] = 0;
}
int main()
{

      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    srand(unsigned(time(NULL)));

    cin >> t >> m;
    k = 1;

    for (int i(0); i < t; i++)
    {
        string word;
        cin >> word;
        if (word[0] == 'a')
        {
            int x;
            cin >> x;
            int p = find(x);
            if (p == -1)
                cout << "NULL\n";
            else
            {
                cout << p << "\n";
            }
            continue;
        }
        if (word[0] == 'e')
        {
            int x;
            cin >> x;
            int p = del(x);
            if (p == -1)
                cout << "ILLEGAL_ERASE_ARGUMENT\n";
            continue;
        }

        turnLeft();
    }

}

// Thu Nov 03 2016 19:41:42 GMT+0300 (MSK)


#include <iostream>
#include <cmath>
#include <complex>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <iomanip>
#include <functional>
#include <iterator>
#include <numeric>

double eps = 1e-9;

#define pb push_back
#define rz(a) resize(a)
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define inf (int)(1e9+7)
#define infll (ll)(1e18+3)
#define sz(x) ((int)x.size())
#define bits(x) __builtin_popcount(x)
#define bitsl(x) __builtin_popcountll(x)
#define rep(i, a, b) for (int (i) = (a); i <= (b); ++(i))
#define forn(i, n) rep(i, 0, ((int)n)-1)
#define INF 200000
#define YES {cout << "Yes" << endl;}
#define NO {cout << "No" << endl;}

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector < ll > vll;
typedef vector<int> vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector<vi> vii;
typedef vector<vi> vvi;
typedef vector<ull> vull;
typedef vector<pii> vpii;

int main() {
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    vi v(m, 0);
    map<int, pii> ma;
    vi free(m, 1);
    free[0] = 1;
    int F = 1;
    forn(i, n) {
        string s;
        cin >> s;
        if (s == "alloc") {
            int k;
            cin >> k;
            bool f = false;
            forn(i, m) {
                if (v[i] == 0) {
                    int j = i;
                    for(; j < m && v[j] == 0; j++);
                    if (j-i >= k) {
                        cout << F << endl;
                        free[F] = 1;
                        ma[F++] = mp(i, i+k-1);
                        rep(j, i, i+k-1) v[j] = 1;
                        f = true;
                        break;
                    }

                }
            }
            if (!f) {
                cout << "NULL" << endl;
            }
        }
        else if (s == "erase") {
            int k;
            cin >> k;
            if (ma.find(k) == ma.end()) {
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
                continue;
            }
            pii p = ma[k];
            ma.erase(k);
            free[k] = 0;
            rep(i, p.F, p.S) v[i] = 0;
        }
        else if (s == "defragment") {
            vi w(m);
            int k = 0;
            for(map<int, pii>::iterator p = ma.begin(); p != ma.end(); ++p) {
                int st = k;
                for(int i = 0; i < p->S.S-p->S.F+1; i++, k++)
                    w[k] = 1;
                p->S.F = st;
                p->S.S = p->S.F-p->S.S+st;

            }
            v = w;
        }
    }

    return 0;
}

// Thu Nov 03 2016 20:59:27 GMT+0300 (MSK)


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <ctime>
#include <iostream>
#include <cmath>
#include <stack>
#include <sstream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cassert>

const long double PI(acosl(-1.0));
long double eps = 1e-9;

#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define inf (int)(1e9+7)
#define infll (ll)(1e18+3)
#define sz(x) ((int)x.size())
#define bits(x) __builtin_popcount(x)
#define bitsl(x) __builtin_popcountll(x)
#define rep(i, a, b) for (int (i) = (a); i <= (b); ++(i))
#define forn(i, n) rep(i, 0, n-1)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector < ll > vll;
typedef vector<int> vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector<vi> vii;
typedef int huint;

const int N = 2 * 1e5;

int t, m;
int a[1000];
pii start[1000];
int k;

int find(int ln)
{
    for (int i(1); i <= m; i++)
    {
        int cnt = 0;
        for (int j(i); j < i + ln; j++)
        {
            if (j > m) break;
            if (a[j] != 0) break;
            cnt++;
        }
        if (cnt == ln)
        {
            start[k] = mp(i,ln);
            for (int j(i); j < i + ln; j++)
                a[j] = k;
            k++;
            return k - 1;
        }
    }
    return -1;
}

int del(int ind)
{
    if (ind < 1 || ind >= k) return -1;
    if (start[ind].F == -1) return -1;
    for (int i(start[ind].F); i < start[ind].F + start[ind].S; i++)
    {
        a[i] = 0;
    }
    start[ind].F = -1;
    return 0;
}
void turnLeft()
{
    vector<int> fl(m+2, 0);
    int cnt = 0;
    for (int i(1); i <= m; i++)
    {
        if (a[i] == 0) cnt++;
        else
        {
            if (fl[a[i]] != 0) continue;
            fl[a[i]] = 1;
            start[a[i]].F -= cnt;
        }
    }
    int stp = 0;
    for (int i(1); i < k; i++)
    {
        if (start[i].F == -1) continue;

        for (int j(start[i].F); j < start[i].F + start[i].S; j++)
        {
            a[j] = i;
            stp = max(j,stp);
        }
    }
    stp++;
    for (int i(stp); i <= m; i++)
        a[i] = 0;
}
int main()
{

      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    srand(unsigned(time(NULL)));

    cin >> t >> m;
    k = 1;

    for (int i(0); i < t; i++)
    {
        string word;
        cin >> word;
        if (word[0] == 'a')
        {
            int x;
            cin >> x;
            int p = find(x);
            if (p == -1)
                cout << "NULL\n";
            else
            {
                cout << p << "\n";
            }
            continue;
        }
        if (word[0] == 'e')
        {
            int x;
            cin >> x;
            int p = del(x);
            if (p == -1)
                cout << "ILLEGAL_ERASE_ARGUMENT\n";
            continue;
        }
        turnLeft();
    }

}

// Thu Nov 03 2016 19:49:08 GMT+0300 (MSK)


#include <iostream>
#include <cmath>
#include <complex>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <iomanip>
#include <functional>
#include <iterator>
#include <numeric>

double eps = 1e-9;

#define pb push_back
#define rz(a) resize(a)
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define inf (int)(1e9+7)
#define infll (ll)(1e18+3)
#define sz(x) ((int)x.size())
#define bits(x) __builtin_popcount(x)
#define bitsl(x) __builtin_popcountll(x)
#define rep(i, a, b) for (int (i) = (a); i <= (b); ++(i))
#define forn(i, n) rep(i, 0, ((int)n)-1)
#define INF 200000
#define YES {cout << "Yes" << endl;}
#define NO {cout << "No" << endl;}

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector < ll > vll;
typedef vector<int> vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector<vi> vii;
typedef vector<vi> vvi;
typedef vector<ull> vull;
typedef vector<pii> vpii;

int main() {
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    vi v(m, 0);
    map<int, pii> ma;
    vi free(m, 1);
    free[0] = 1;
    int F = 1;
    forn(i, n) {
        string s;
        cin >> s;
        if (s == "alloc") {
            int k;
            cin >> k;
            bool f = false;
            forn(i, m) {
                if (v[i] == 0) {
                    int j = i;
                    for(; j < m && v[j] == 0; j++);
                    if (j-i >= k) {
                        cout << F << endl;
                        free[F] = 1;
                        ma[F++] = mp(i, i+k-1);
                        rep(j, i, i+k-1) v[j] = 1;
                        f = true;
                        break;
                    }

                }
            }
            if (!f) {
                cout << "NULL" << endl;
            }
        }
        else if (s == "erase") {
            int k;
            cin >> k;
            if (ma.find(k) == ma.end()) {
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
                continue;
            }
            pii p = ma[k];
            ma.erase(k);
            free[k] = 0;
            rep(i, p.F, p.S) v[i] = 0;
        }
        else if (s == "defragment") {
            vi w(m);
            int k = 0;
            for(map<int, pii>::iterator p = ma.begin(); p != ma.end(); ++p) {
                int st = k;
                for(int i = 0; i < p->S.S-p->S.F+1; i++, k++)
                    w[k] = 1;
                p->S.F = st;
                p->S.S = k-1;

            }
            v = w;
        }
    }

    return 0;
}

// Thu Nov 03 2016 21:12:55 GMT+0300 (MSK)


//Author: Artem Romanov
#include <stdio.h>
#include <bits/stdc++.h>
//#define TASK "file"

#define F   first
#define S   second
#define y0  y84678
#define y1  y53021

using namespace std;
typedef double dbl;

const dbl PI = 3.141592653589793238462643383279502884L;
const dbl E = 2.718281828459045235360287471352662498L;
const dbl EPS = 1e-12L;

int t, m, n, x, k;
string s;
int a[100] = {};

void defragment() {
    vector<int> t;
    for (int i = 0; i < m; i++) {
        if (a[i]) {
            t.push_back(a[i]);
        }
    }
    fill(a, a + m, 0);
    for (int i = 0; i < t.size(); i++) {
        a[i] = a[i];
    }
}

int alloc(int n) {
    for (int i = 0; i < m; i++) {
        int cnt = 0;
        for (int j = i; j < m; j++) {
            if (a[j] != 0) {
                break;
            } else {
                ++cnt;
            }
        }
        if (cnt >= n) {
            ++k;
            for (int j = 0; j < n; j++) {
                a[i + j] = k;
            }
            return k;
        }
    }
    return 0;
}

bool erase(int x) {
    for (int i = 0; i < m; ++i) {
        if (a[i] == x) {
            for (int j = i; j < m; j++) {
                if (a[j] != x) {
                    break;
                } else {
                    a[j] = 0;
                }
            }
            return true;
        }
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.precision(11); cout.setf(ios::fixed);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#elif defined(TASK)
    freopen(TASK".in", "r", stdin);
    freopen(TASK".out", "w", stdout);
#endif

    k = 0;
    cin >> t >> m;
    for (int i = 0; i < t; i++) {
        cin >> s;
        if (s == "defragment") {
            defragment();
        } else if (s == "alloc") {
            cin >> n;
            int t = alloc(n);
            if (t == 0) {
                cout << "NULL\n";
            } else {
                cout << t << '\n';
            }
        } else if (s == "erase") {
            cin >> x;
            if (!erase(x)) {
                cout << "ILLEGAL_ERASE_ARGUMENT\n";
            }
        }
    }
    return 0;
}

// Thu Nov 03 2016 19:55:16 GMT+0300 (MSK)


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
long long gcd(long long a, long long b) {
	if (a > b) swap(a, b);
	while (a) {
		b %= a;
		swap(a, b);
	}
	return b;
}
int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	vector<int> a(m + 1, 0);
	int id = 1;
	for (int z = 0; z < n; z++) {
		string s;
		cin >> s;
		if (s == "alloc") {
			int l,aa=1;
			cin >> l;
			for (int j = 1; j <= m; j++) {
				if (!a[j]) {
					int f = 0;
					while (f !=l  && j <= m && !a[j]) {
						f++;
						j++;
					}
					if (f == l){
						while ( f ) a[j - (f--)] = id;
						cout << id++ << endl;
						aa = 0;
						j = m + 1;
					}
				}
			}
			if (aa) cout << "NULL" << endl;
		}
		if (s == "erase") {
			int l;
			cin >> l;
			bool zz = false;
			int g = 1;
			if(l!=0)
			for (; g <= m; g++) if (a[g] == l) {
				while (g <= m && a[g] == l) a[g++] = 0;
				zz = true;
			}
			if (!zz) {
				cout << "ILLEGAL_ERASE_ARGUMENT"<<endl;
			}
		}
		if (s == "defragment") {
			int k = 0;
			for (int i= 1; i <= m - k; i++) {
				while (i + k <= m && !a[i + k]) k++;
				if (i + k <= m) swap(a[i],a[i + k]);
			}
		}
	}
}

// Thu Nov 03 2016 21:52:31 GMT+0300 (MSK)


#include <bits/stdc++.h>
#include <cstring>

#define PI  acosl(-1.0)
#define eps 1e-7
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using namespace std;

int t, m;
int memory[123];

int block_num[123][123];
int total;
vector <int> blocks_len;
int alloc (int cnt)
{
    for (int i = 1; i <= m; i++)
    {

        if (memory[i] == 1) continue;

        int last = i;
        int pos = i;
        int kol = 0;

        while (pos <= m  && memory[pos] == 0 && cnt > kol)
        {
            pos++;
            kol++;
        }

        if (kol > 0) i = pos - 1;

        if (kol >= cnt)
        {
            total++;
            pos--;
            //cout << last << " " << pos << endl;
            for (int x = last; x <= pos; x++)
            {
                memory[x] = 1;
            }
            block_num[last][pos] = total;
            blocks_len.push_back(pos - last + 1);
            return total;
        }
    }

    return -1;
}

void print ()
{
    for (int i = 1; i <= m; i++)
        cout << memory[i] << " ";
    cout << endl;
}
bool er (int num)
{
    int cnt = 0;

    for (int i = 1; i <= 100; i++)
        for (int j = i; j <= 100; j++)
        {
                if (block_num[i][j] == num)
                {
                    for (int x = i; x <= j; x++)
                        memory[x] = 0;
                    auto it = blocks_len.begin();
                    for (int k = 0; k < num - 1; k++)
                        it++;
                        if (blocks_len.size())
                    blocks_len.erase(it);
                    return 1;
                }
        }
    return 0;
    for (int i = 1; i <= m; i++)
    {
        int kol = 0;
        if (memory[i] == 1 && cnt + 1 < num)
        {
            cnt++;
            i += blocks_len[cnt - 1];
            i--;
        }
        if (memory[i] == 1 && cnt + 1 == num)
        {
           // cout << "FUCK" << endl;
            kol = 0;

            while (memory[i] == 1 && kol < blocks_len[cnt])
            {
              //  cout << "i = " << i << endl;
                kol++;
                memory[i] = 0;
                i++;
            }
            auto it = blocks_len.begin();
            for (int j = 0; j < num - 1; j++)
                it++;
            blocks_len.erase(it);
            i--;
            return 1;
        }
    }

    return 0;
}

void defragment ()
{
    int cnt = 0;
    for (int i = 1; i <= m; i++)
        if (memory[i]) cnt++;
    for (int i = 1; i <= m; i++)
        memory[i] = 0;
    for (int i = 1;cnt > 0 && i <= m; i++)
    {
        cnt--;
        memory[i] = 1;
    }
}

int main ()
{
    ios_base::sync_with_stdio(0);
   // cin.tie(nullptr);cout.tie(nullptr);
    ///cout << fixed << setprecision(20);
    ///freopen("arrayfactory.in", "r", stdin);
    ///freopen("arrayfactory.out", "w", stdout);

    cin >> t >> m;

    for (int i = 0; i < t; i++)
    {
        string s;
        cin >> s;
        if (s == "alloc")
        {
            int x;
            cin >> x;
            int f = alloc(x);
            if (f == -1) cout << "NULL\n";
            else cout << f << '\n';
        }
        else if (s == "erase")
        {
            int x;
            cin >> x;

            bool ok = er(x);
            if (!ok)
            {
                cout << "ILLEGAL_ERASE_ARGUMENT\n";
            }
        }
        else
            defragment();
       // print();
    }

    //for (int i = 0; i < 2; i++)
    //    cout << blocks_len[i] << " ";
    return 0;
}

// Thu Nov 03 2016 20:58:00 GMT+0300 (MSK)


//Author: Artem Romanov
#include <stdio.h>
#include <bits/stdc++.h>
//#define TASK "file"

#define F   first
#define S   second
#define y0  y84678
#define y1  y53021

using namespace std;
typedef double dbl;

const dbl PI = 3.141592653589793238462643383279502884L;
const dbl E = 2.718281828459045235360287471352662498L;
const dbl EPS = 1e-12L;

int64_t t, m, n, x, k;
string s;
int64_t a[1000] = {};

void defragment() {
    vector<int64_t> tmp;
    for (int64_t i = 0; i < m; i++) {
        if (a[i]) {
            tmp.push_back(a[i]);
        }
    }
    fill(a, a + m, 0);
    for (int64_t i = 0; i < tmp.size(); i++) {
        a[i] = tmp[i];
    }
}

int64_t alloc(int64_t n) {
    for (int64_t i = 0; i < m; i++) {
        int64_t cnt = 0;
        for (int64_t j = i; j < m; j++) {
            if (a[j] != 0) {
                break;
            } else {
                ++cnt;
            }
        }
        if (cnt >= n) {
            ++k;
            for (int64_t j = 0; j < n; j++) {
                a[i + j] = k;
            }
            return k;
        }
    }
    return 0;
}

bool erase(int64_t x) {
    for (int64_t i = 0; i < m; ++i) {
        if (a[i] == x) {
            for (int64_t j = i; j < m; j++) {
                if (a[j] != x) {
                    break;
                } else {
                    a[j] = 0;
                }
            }
            return true;
        }
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.precision(11); cout.setf(ios::fixed);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#elif defined(TASK)
    freopen(TASK".in", "r", stdin);
    freopen(TASK".out", "w", stdout);
#endif

    k = 0;
    cin >> t >> m;
    for (int64_t i = 0; i < t; i++) {
        cin >> s;
        if (s == "defragment") {
            defragment();
        } else if (s == "alloc") {
            cin >> n;
            int64_t tmp = alloc(n);
            if (tmp == 0) {
                cout << "NULL\n";
            } else {
                cout << tmp << '\n';
            }
        } else if (s == "erase") {
            cin >> x;
            if (!erase(x)) {
                cout << "ILLEGAL_ERASE_ARGUMENT\n";
            }
        }
        /*for (int64_t j = 0; j < m; j++) {
        cout << a[j] << ' ';
        }
        cout << '\n';*/
    }
    return 0;
}

// Thu Nov 03 2016 21:05:28 GMT+0300 (MSK)


#include <bits/stdc++.h>

using namespace std;
const int maxn = 105;
map<int, int> ma;
char op[15];
vector<int> ivec;
int main()
{
    int t, m, n, num = 0;
    scanf("%d %d", &t, &m);
    while(t--)
    {
        scanf("%s", op);
        if (op[0] == 'a')
        {
            scanf("%d", &n);
            if (m - n >= 0)
            {
                ma[++num] = n;
                m -= n;
                cout << num << endl;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if (op[0] == 'e')
        {
            scanf("%d", &n);
            if (n < 0)
            {
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
                continue;
            }
            else if (ma[n] != 0)
            {
                ivec.push_back(ma[n]);
                ma[n] = 0;
            }
            else
            {
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
            }
        }
        else if (!ivec.empty())
        {
            for(int i = 0; i <= ivec.size(); ++i)
            {
                m += ivec[i];
            }
            ivec.clear();
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 105;
map<int, int> ma;
char op[15];
vector<int> ivec;
int main()
{
    int t, m, n, num = 0;
    scanf("%d %d", &t, &m);
    while(t--)
    {
        scanf("%s", op);
        if (op[0] == 'a')
        {
            scanf("%d", &n);
            if (m - n >= 0)
            {
                ma[++num] = n;
                m -= n;
                cout << num << endl;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if (op[0] == 'e')
        {
            scanf("%d", &n);
            if (ma[n] != 0)
            {
                ivec.push_back(ma[n]);
                ma[n] = 0;
            }
            else
            {
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
            }
        }
        else
        {
            for(int i = 0; i <= ivec.size(); ++i)
            {
                m += ivec[i];
            }
            ivec.clear();
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t, m, n, num = 1;
int ma[105];
char op[15];
bool check(int n, int num)
{
    for(int i = 1; i <= m-n+1; ++i)
    {
        bool flag = false;
        for(int j = i; j < i+n; ++j)
        {
            if (ma[j])
                flag = true;
        }
        if (!flag)
        {
            for(int j = i; j < i+n; ++j)
                ma[j] = num;
            return true;
        }
    }
    return false;
}
int main()
{
    scanf("%d %d", &t, &m);
    memset(ma, 0, sizeof(ma));
    while(t--)
    {
        scanf(" %s", op);
        if (op[0] == 'a')
        {
            scanf("%d", &n);
            if (check(n, num))
            {
                cout << num << endl;
                num++;
            }
            else
                cout << "NULL" << endl;
        }
        else if (op[0] == 'e')
        {
            scanf("%d", &n);
            if (n == 0)
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
            else
            {
                bool flag = false;
                for(int i = 1; i <= m; ++i)
                {
                    if (ma[i] == n)
                    {
                        ma[i] = 0;
                        flag = true;
                    }
                }
                if (!flag)
                    cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
            }
        }
        else
        {
            int i, j = 1;
            while(j <= m)
            {
                ma[i] = ma[j];
                if (ma[i])
                {
                    if (j > i)
                        ma[j] = 0;
                    ++i;
                }
                ++j;
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M 100+5
int mem[M];  char s[15];
int t,m;
int check(int x,int c){
    int i,j,f;
    for(i=1;i<=m-x+1;i++){
        f=0;
        for(j=i;j<i+x;j++)
            if(mem[j]!=0)f=1;
        if(f==0){
            for(j=i;j<i+x;j++)
                mem[j]=c;
            return 1;
        }
    }
    return 0;
}
int main(){
    int i,j,c,x,f;
    while(~scanf("%d %d",&t,&m)){
        c=1;
        memset(mem,0,sizeof(mem));
        while(t--){
            scanf("%s",s);
            if(s[0]=='a'){
                scanf("%d",&x);
                if(check(x,c)==1)printf("%d\n",c++);
                else puts("NULL");
            }else if(s[0]=='e'){
                scanf("%d",&x);
                if(x==0)puts("ILLEGAL_ERASE_ARGUMENT");
                else{
                    f=0;
                    for(i=1;i<=m;i++)
                        if(mem[i]==x){
                            mem[i]=0;
                            f=1;
                        }
                    if(f==0)puts("ILLEGAL_ERASE_ARGUMENT");
                }
            }else if(s[0]=='d'){
                i=j=1;
                while(j<=m){
                    mem[i]=mem[j];
                    if(mem[i]!=0){
                        if(j>i)mem[j]=0;
                        i++;
                    }
                    j++;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
map<int, int> ma;
char op[15];
vector<int> ivec;
int main()
{
    int t, m, n, num = 0;
    scanf("%d %d", &t, &m);
    while(t--)
    {
        scanf("%s", op);
        if (op[0] == 'a')
        {
            scanf("%d", &n);
            if (m - n >= 0)
            {
                ma[++num] = n;
                m -= n;
                cout << num << endl;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if (op[0] == 'e')
        {
            scanf("%d", &n);
            if (n < 0)
            {
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
                continue;
            }
            else if (ma[n] != 0)
            {
                if (n == num)
                {
                    m += ma[n];
                    ma[n] = 0;
                }
                else
                {
                    ivec.push_back(ma[n]);
                    ma[n] = 0;
                }
            }
            else
            {
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
            }
        }
        else if (!ivec.empty())
        {
            for(int i = 0; i < ivec.size(); ++i)
            {
                m += ivec[i];
            }
            ivec.clear();
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 105;
map<int, int> ma;
char op[15];
vector<int> ivec;
int main()
{
    int t, m, n, num = 0;
    scanf("%d %d", &t, &m);
    while(t--)
    {
        scanf("%s", op);
        if (op[0] == 'a')
        {
            scanf("%d", &n);
            if (m - n >= 0)
            {
                ma[++num] = n;
                m -= n;
                cout << num << endl;
            }
            else
            {
                cout << "NULL" << endl;
            }
        }
        else if (op[0] == 'e')
        {
            scanf("%d", &n);
            if (n < 0)
            {
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
                continue;
            }
            else if (ma[n] != 0)
            {
                if (n == num)
                {
                    m += ma[n];
                    ma[n] = 0;
                }
                else
                {
                    ivec.push_back(ma[n]);
                    ma[n] = 0;
                }
            }
            else
            {
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
            }
        }
        else if (!ivec.empty())
        {
            for(int i = 0; i < ivec.size(); ++i)
            {
                m += ivec[i];
            }
            ivec.clear();
        }
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int t, m;
    cin >> t >> m;
    string command;
    vector<int> memory(m);
    vector<char> usedId(2 * m + 1);
    int id = 1;

    for (int i = 0; i < t; ++i)
    {
        cin >> command;

        if (command[0] == 'a')
        {
            int blockS;
            cin >> blockS;
            int zeroCnt = 0, oldId = id;

            for (int j = 0; j < m; ++j)
            {
                if (memory[j])
                {
                    zeroCnt = 0;
                }
                else
                {
                    ++zeroCnt;
                    if (zeroCnt == blockS)
                    {
                        for (int k = j - zeroCnt + 1; k <= j; ++k)
                        {
                            memory[k] = id;
                        }

                        cout << id << endl;

                        usedId[id++] = 1;

                        break;
                    }
                }
            }

            if (oldId == id)
            {
                cout << "NULL\n";
            }
        }
        else
        {
            if (command[0] == 'e')
            {
                int eraseId;
                cin >> eraseId;
                if (eraseId < 1 || eraseId > m || !usedId[eraseId])
                {
                    cout << "ILLEGAL_ERASE_ARGUMENT\n";
                }
                else
                {
                    usedId[eraseId] = 0;

                    for (int j = 0; j < m; ++j)
                    {
                        if (memory[j] == eraseId)
                        {
                            memory[j] = 0;
                        }
                    }
                }
            }
            else
            {
                vector<int> buffer;

                for (int j = 0; j < m; ++j)
                {
                    if (memory[j])
                    {
                        buffer.push_back(memory[j]);
                    }
                }
                for (int j = 0; j < buffer.size(); ++j)
                {
                    memory[j] = buffer[j];
                }
                for (int j = buffer.size(); j < m; ++j)
                {
                    memory[j] = 0;
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int t, m;
    cin >> t >> m;
    string command;
    vector<int> memory(m);
    vector<char> usedId((t + 3) / 2);
    int id = 1;

    for (int i = 0; i < t; ++i)
    {
        cin >> command;

        if (command[0] == 'a')
        {
            int blockS;
            cin >> blockS;
            int zeroCnt = 0, oldId = id;

            for (int j = 0; j < m; ++j)
            {
                if (memory[j])
                {
                    zeroCnt = 0;
                }
                else
                {
                    ++zeroCnt;
                    if (zeroCnt == blockS)
                    {
                        for (int k = j - zeroCnt + 1; k <= j; ++k)
                        {
                            memory[k] = id;
                        }

                        cout << id << endl;

                        usedId[id++] = 1;

                        break;
                    }
                }
            }

            if (oldId == id)
            {
                cout << "NULL\n";
            }
        }
        else
        {
            if (command[0] == 'e')
            {
                int eraseId;
                cin >> eraseId;
                if (eraseId < 1 || eraseId > m || !usedId[eraseId])
                {
                    cout << "ILLEGAL_ERASE_ARGUMENT\n";
                }
                else
                {
                    usedId[eraseId] = 0;

                    for (int j = 0; j < m; ++j)
                    {
                        if (memory[j] == eraseId)
                        {
                            memory[j] = 0;
                        }
                    }
                }
            }
            else
            {
                vector<int> buffer;

                for (int j = 0; j < m; ++j)
                {
                    if (memory[j])
                    {
                        buffer.push_back(memory[j]);
                    }
                }
                for (int j = 0; j < buffer.size(); ++j)
                {
                    memory[j] = buffer[j];
                }
                for (int j = buffer.size(); j < m; ++j)
                {
                    memory[j] = 0;
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int t, m;
    cin >> t >> m;
    string command;
    vector<int> memory(m);
    vector<char> usedId(m + 1);
    int id = 1;

    for (int i = 0; i < t; ++i)
    {
        cin >> command;

        if (command[0] == 'a')
        {
            int blockS;
            cin >> blockS;
            int zeroCnt = 0, oldId = id;

            for (int j = 0; j < m; ++j)
            {
                if (memory[j])
                {
                    zeroCnt = 0;
                }
                else
                {
                    ++zeroCnt;
                    if (zeroCnt == blockS)
                    {
                        for (int k = j - zeroCnt + 1; k <= j; ++k)
                        {
                            memory[k] = id;
                        }

                        cout << id << endl;

                        usedId[id++] = 1;

                        break;
                    }
                }
            }

            if (oldId == id)
            {
                cout << "NULL\n";
            }
        }
        else
        {
            if (command[0] == 'e')
            {
                int eraseId;
                cin >> eraseId;
                if (eraseId < 1 || eraseId > m || !usedId[eraseId])
                {
                    cout << "ILLEGAL_ERASE_ARGUMENT\n";
                }
                else
                {
                    usedId[eraseId] = 0;

                    for (int j = 0; j < m; ++j)
                    {
                        if (memory[j] == eraseId)
                        {
                            memory[j] = 0;
                        }
                    }
                }
            }
            else
            {
                vector<int> buffer;

                for (int j = 0; j < m; ++j)
                {
                    if (memory[j])
                    {
                        buffer.push_back(memory[j]);
                    }
                }
                for (int j = 0; j < buffer.size(); ++j)
                {
                    memory[j] = buffer[j];
                }
                for (int j = buffer.size(); j < m; ++j)
                {
                    memory[j] = 0;
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int t, m;
    cin >> t >> m;
    string command;
    vector<int> memory(m);
    vector<char> usedId((t + 3) / 2);
    int id = 1;

    for (int i = 0; i < t; ++i)
    {
        cin >> command;

        if (command[0] == 'a')
        {
            int blockS;
            cin >> blockS;
            int zeroCnt = 0, oldId = id;

            for (int j = 0; j < m; ++j)
            {
                if (memory[j])
                {
                    zeroCnt = 0;
                }
                else
                {
                    ++zeroCnt;
                    if (zeroCnt == blockS)
                    {
                        for (int k = j - zeroCnt + 1; k <= j; ++k)
                        {
                            memory[k] = id;
                        }

                        cout << id << endl;

                        usedId[id++] = 1;

                        break;
                    }
                }
            }

            if (oldId == id)
            {
                cout << "NULL\n";
            }
        }
        else
        {
            if (command[0] == 'e')
            {
                int eraseId;
                cin >> eraseId;
                if (eraseId < 1 || eraseId >= id || !usedId[eraseId])
                {
                    cout << "ILLEGAL_ERASE_ARGUMENT\n";
                }
                else
                {
                    usedId[eraseId] = 0;

                    for (int j = 0; j < m; ++j)
                    {
                        if (memory[j] == eraseId)
                        {
                            memory[j] = 0;
                        }
                    }
                }
            }
            else
            {
                vector<int> buffer;

                for (int j = 0; j < m; ++j)
                {
                    if (memory[j])
                    {
                        buffer.push_back(memory[j]);
                    }
                }
                for (int j = 0; j < buffer.size(); ++j)
                {
                    memory[j] = buffer[j];
                }
                for (int j = buffer.size(); j < m; ++j)
                {
                    memory[j] = 0;
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int t, m;
    cin >> t >> m;
    string command;
    vector<int> memory(m);
    vector<char> usedId(m + 1);
    int id = 1;

    for (int i = 0; i < t; ++i)
    {
        cin >> command;

        if (command[0] == 'a')
        {
            int blockS;
            cin >> blockS;
            int zeroCnt = 0, oldId = id;

            for (int j = 0; j < m; ++j)
            {
                if (memory[j])
                {
                    zeroCnt = 0;
                }
                else
                {
                    ++zeroCnt;
                    if (zeroCnt == blockS)
                    {
                        for (int k = j - zeroCnt + 1; k <= j; ++k)
                        {
                            memory[k] = id;
                        }

                        cout << id << endl;

                        usedId[id++] = 1;

                        break;
                    }
                }
            }

            if (oldId == id)
            {
                cout << "NULL\n";
            }
        }
        else
        {
            if (command[0] == 'e')
            {
                int eraseId;
                cin >> eraseId;
                if (!usedId[eraseId])
                {
                    cout << "ILLEGAL_ERASE_ARGUMENT\n";
                }
                else
                {
                    usedId[eraseId] = 0;

                    for (int j = 0; j < m; ++j)
                    {
                        if (memory[j] == eraseId)
                        {
                            memory[j] = 0;
                        }
                    }
                }
            }
            else
            {
                vector<int> buffer;

                for (int j = 0; j < m; ++j)
                {
                    if (memory[j])
                    {
                        buffer.push_back(memory[j]);
                    }
                }
                for (int j = 0; j < buffer.size(); ++j)
                {
                    memory[j] = buffer[j];
                }
                for (int j = buffer.size(); j < m; ++j)
                {
                    memory[j] = 0;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

set<char> ss;
map<char, int> p;

int main(){
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; ++i) ss.insert(s[i]);
    int num = ss.size();
    int ans = 0x3f3f3f3f;
    for(int r = 0, l = 0; r < n; ++r){
        ++p[s[r]];
        while(p[s[l]] > 1 && l < r)
            --p[s[l]], ++l;
        if(p.size() == num) ans = min(ans, r-l+1);
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 111;
int n, k, mem[maxn];

int main(){
    int counter = 0;
	scanf("%d %d", &n, &k);
	while(n--){
		char s[11];
		int x;
		scanf("%s", s);
		if(s[0] == 'a' || s[0] == 'e'){
			scanf("%d", &x);
			if(s[0] == 'a'){
                bool flag = false;
                int tmp = 0;
                for(int i = 0; i < k; ++i){
                    if(mem[i] == 0) ++tmp;
                    else tmp = 0;
                    if(tmp == x){
                        printf("%d\n", ++counter);
                        int index = i;
                        while(tmp--) mem[index--] = counter;
                        flag = true;
                        break;
                    }
                }
                if(!flag) puts("NULL");
			}
			else{
                bool flag = false;
                for(int i = 0; i < k; ++i)
                    if(mem[i] == x){
                        mem[i] = 0;
                        flag = true;
                    }
                if(!flag) puts("ILLEGAL_ERASE_ARGUMENT");
			}
		}
		else{
            for(int i = 0; i < k; ++i){
                if(mem[i] != 0){
                    int j = i;
                    while(j > 0 && mem[j-1] == 0) --j;
                    swap(mem[i], mem[j]);
                }
            }
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 111;
int n, k, mem[maxn];

int main(){
    int counter = 0;
	scanf("%d %d", &n, &k);
	while(n--){
		char s[11];
		int x;
		scanf("%s", s);
		if(s[0] == 'a' || s[0] == 'e'){
			scanf("%d", &x);
			if(s[0] == 'a'){
                bool flag = false;
                int tmp = 0;
                for(int i = 0; i < k; ++i){
                    if(mem[i] == 0) ++tmp;
                    else tmp = 0;
                    if(tmp == x){
                        printf("%d\n", ++counter);
                        int index = i;
                        while(tmp--) mem[index--] = counter;
                        flag = true;
                        break;
                    }
                }
                if(!flag) puts("NULL");
			}
			else{
                bool flag = false;
                for(int i = 0; i < k; ++i)
                    if(mem[i] == x){
                        mem[i] = 0;
                        flag = true;
                    }
                if(!flag) puts("ILLEGAL_ERASE_ARGUMENT");
			}
		}
		else{
            int j = 0;
            for(int i = 0; i < k; ++i){
                while(mem[j] != 0) ++j;
                if(mem[i] != 0) swap(mem[i], mem[j]);
            }
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 111;
int n, k, mem[maxn];

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    int counter = 0;
	scanf("%d %d", &n, &k);
	while(n--){
		char s[11];
		int x;
		scanf("%s", s);
		if(s[0] == 'a' || s[0] == 'e'){
			scanf("%d", &x);
			if(s[0] == 'a'){
                bool flag = false;
                int tmp = 0;
                for(int i = 0; i < k; ++i){
                    if(mem[i] == 0) ++tmp;
                    else tmp = 0;
                    if(tmp == x){
                        printf("%d\n", ++counter);
                        int index = i;
                        while(tmp--) mem[index--] = counter;
                        flag = true;
                        break;
                    }
                }
                if(!flag) puts("NULL");
			}
			else{
                bool flag = false;
                for(int i = 0; i < k; ++i)
                    if(mem[i] == x){
                        mem[i] = 0;
                        flag = true;
                    }
                if(!flag) puts("ILLEGAL_ERASE_ARGUMENT");
			}
		}
		else{
            for(int i = 0; i < k; ++i){
                if(mem[i] != 0){
                    int j = i;
                    while(j > 0 && mem[j-1] == 0) --j;
                    swap(mem[i], mem[j]);
                }
            }
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 111;
int n, k, mem[maxn];

int main(){
    int counter = 0;
	scanf("%d %d", &n, &k);
	while(n--){
		char s[11];
		int x;
		scanf("%s", s);
		if(s[0] == 'a' || s[0] == 'e'){
			scanf("%d", &x);
			if(s[0] == 'a'){
                bool flag = false;
                int tmp = 0;
                for(int i = 0; i < k; ++i){
                    if(mem[i] == 0) ++tmp;
                    else tmp = 0;
                    if(tmp == x){
                        printf("%d\n", ++counter);
                        int index = i;
                        while(tmp--) mem[index--] = counter;
                        flag = true;
                        break;
                    }
                }
                if(!flag) puts("NULL");
			}
			else{
                bool flag = false;
                for(int i = 0; i < k; ++i)
                    if(mem[i] == x){
                        mem[i] = 0;
                        flag = true;
                    }
                if(!flag) puts("ILLEGAL_ERASE_ARGUMENT");
			}
		}
		else{
            int j = 0;
            for(int i = 0; i < k; ++i){
                if(mem[i] != 0) swap(mem[i], mem[j]);
                while(mem[j] != 0) ++j;
            }
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 111;
int n, k, mem[maxn];

int main(){
    int counter = 0;
	scanf("%d %d", &n, &k);
	while(n--){
		char s[11];
		int x;
		scanf("%s", s);
		if(s[0] == 'a' || s[0] == 'e'){
			scanf("%d", &x);
			if(s[0] == 'a'){
                bool flag = false;
                int tmp = 0;
                for(int i = 0; i < k; ++i){
                    if(mem[i] == 0) ++tmp;
                    else tmp = 0;
                    if(tmp == x){
                        printf("%d\n", ++counter);
                        int index = i;
                        while(tmp--) mem[index--] = counter;
                        flag = true;
                        break;
                    }
                }
                if(!flag) puts("NULL");
			}
			else{
                bool flag = false;
                for(int i = 0; i < k; ++i)
                    if(mem[i] == x){
                        mem[i] = 0;
                        flag = true;
                    }
                if(!flag) puts("ILLEGAL_ERASE_ARGUMENT");
			}
		}
		else{
            int j = 0;
            for(int i = 0; i < k; ++i){
                while(mem[j] != 0) ++j;
                if(mem[i] != 0) swap(mem[i], mem[j]);
            }
		}
		for(int i = 0; i < k; ++i)
            cout << mem[i] << " ";
        cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 111;
int n, k, mem[maxn];

int main(){
    int counter = 0;
	scanf("%d %d", &n, &k);
	while(n--){
		char s[11];
		int x;
		scanf("%s", s);
		if(s[0] == 'a' || s[0] == 'e'){
			scanf("%d", &x);
			if(s[0] == 'a'){
                bool flag = false;
                int tmp = 0;
                for(int i = 0; i < k; ++i){
                    if(mem[i] == 0) ++tmp;
                    else tmp = 0;
                    if(tmp == x){
                        printf("%d\n", ++counter);
                        int index = i;
                        while(tmp--) mem[index--] = counter;
                        flag = true;
                        break;
                    }
                }
                if(!flag) puts("NULL");
			}
			else{
                bool flag = false;
                for(int i = 0; i < k; ++i){
                    if(x == 0) break;
                    if(mem[i] == x){
                        mem[i] = 0;
                        flag = true;
                    }
                }
                if(!flag) puts("ILLEGAL_ERASE_ARGUMENT");
			}
		}
		else{
            for(int i = 0; i < k; ++i){
                if(mem[i] != 0){
                    int j = i;
                    while(j > 0 && mem[j-1] == 0) --j;
                    swap(mem[i], mem[j]);
                }
            }
		}
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <vector>

using namespace std;
using ii = pair<int, int>;

#define MAX 1100

int mem[MAX];
int id = 0;

int main()
{
    memset(mem, 0, sizeof mem);

    int t, m;
    cin >> t >> m;

    while (t--)
    {
        string cmd;
        cin >> cmd;

#ifndef ONLINE_JUDGE
printf("mem = ");
for (int i = 1; i <= m; ++i)
printf("%d%c", mem[i], " \n"[i == m]);
#endif
        if (cmd == "alloc")
        {
            int size;
            cin >> size;

#ifndef ONLINE_JUDGE
cout << "alloc, size = " << size << endl;
#endif
            int block = 0, pos;

            for (int i = 1; i <= m; ++i)
            {
                if (mem[i] == 0)
                    ++block;
                else
                    block = 0;

                if (block == size)
                {
                    pos = i - block + 1;
                    break;
                }
            }

#ifndef ONLINE_JUDGE
cout << "size = " << size << ", pos = " << pos << endl;
#endif
            if (block == size)
            {
                ++id;

                for (int i = 0; i < size; ++i)
                    mem[i + pos] = id;

                cout << id << endl;
            }
            else
                cout << "NULL" << endl;
        } else if (cmd == "erase")
        {
            int block_id;
            cin >> block_id;

#ifndef ONLINE_JUDGE
cout << "erase, id = " << block_id << endl;
#endif
            int erased = 0;

            for (int i = 1; i <= m; ++i)
                if (mem[i] == block_id)
                {
                    ++erased;
                    mem[i] = 0;
                }

            if (erased == 0)
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
        } else
        {
#ifndef ONLINE_JUDGE
cout << "defrag" << endl;
#endif
            int last = 0, count = 0;
            vector<ii> hs;

            for (int i = 1; i <= m + 1; ++i)
            {
                if (mem[i] == last)
                    ++count;
                else
                {
                    if (count > 0 and last > 0)
                        hs.push_back(ii(last, count));

                    count = 1;
                    last = mem[i];
                }
            }

            int pos = 1;

            for (auto p : hs)
            {
                for (int i = 0; i < p.second; ++i)
                    mem[pos++] = p.first;
            }

            while (pos <= m)
                mem[pos++] = 0;
        }
    }

    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>

using namespace std;
using ii = pair<int, int>;

#define MAX 110

int mem[MAX];
int id = 0;

int main()
{
    memset(mem, 0, sizeof mem);

    int t, m;
    cin >> t >> m;

    while (t--)
    {
        string cmd;
        cin >> cmd;

#ifndef ONLINE_JUDGE
printf("mem = ");
for (int i = 1; i <= m; ++i)
printf("%d%c", mem[i], " \n"[i == m]);
#endif
        if (cmd == "alloc")
        {
            int size;
            cin >> size;

#ifndef ONLINE_JUDGE
cout << "alloc, size = " << size << endl;
#endif
            int block = 0, pos;

            for (int i = 1; i <= m; ++i)
            {
                if (mem[i] == 0)
                    ++block;
                else
                    block = 0;

                if (block == size)
                {
                    pos = i - block + 1;
                    break;
                }
            }

#ifndef ONLINE_JUDGE
cout << "size = " << size << ", pos = " << pos << endl;
#endif
            if (block == size)
            {
                ++id;

                for (int i = 0; i < size; ++i)
                    mem[i + pos] = id;

                cout << id << endl;
            }
            else
                cout << "NULL" << endl;
        } else if (cmd == "erase")
        {
            int block_id;
            cin >> block_id;

#ifndef ONLINE_JUDGE
cout << "erase, idi = " << block_id << endl;
#endif
            int erased = 0;

            for (int i = 1; i <= m; ++i)
                if (mem[i] == block_id)
                {
                    ++erased;
                    mem[i] = 0;
                }

            if (erased == 0)
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
        } else
        {
#ifndef ONLINE_JUDGE
cout << "defrag" << endl;
#endif
            int last = 0, count = 0;
            vector<ii> hs;

            for (int i = 1; i <= m + 1; ++i)
            {
                if (mem[i] == last)
                    ++count;
                else
                {
                    if (count > 0 and last > 0)
                        hs.push_back(ii(last, count));

                    count = 1;
                    last = mem[i];
                }
            }

            int pos = 1;

            for (auto p : hs)
            {
                for (int i = 0; i < p.second; ++i)
                    mem[pos++] = p.first;
            }

            while (pos <= m)
                mem[pos++] = 0;
        }
    }

    return 0;
}


#include <iostream>
#include <cstring>

using namespace std;

#define MAX 110

int mem[MAX];
int id = 0;

int main()
{
    memset(mem, 0, sizeof mem);

    int t, m;
    cin >> t >> m;

    while (t--)
    {
        string cmd;
        cin >> cmd;

#ifndef ONLINE_JUDGE
printf("mem = ");
for (int i = 1; i <= m; ++i)
printf("%d%c", mem[i], " \n"[i == m]);
#endif
        if (cmd == "alloc")
        {
            int size;
            cin >> size;

#ifndef ONLINE_JUDGE
cout << "alloc, size = " << size << endl;
#endif
            int block = 0, pos;

            for (int i = 1; i <= m; ++i)
            {
                if (mem[i] == 0)
                    ++block;
                else
                    block = 0;

                if (block == size)
                {
                    pos = i - block + 1;
                    break;
                }
            }

#ifndef ONLINE_JUDGE
cout << "size = " << size << ", pos = " << pos << endl;
#endif
            if (block == size)
            {
                ++id;

                for (int i = 0; i < size; ++i)
                    mem[i + pos] = id;

                cout << id << endl;
            }
            else
                cout << "NULL" << endl;
        } else if (cmd == "erase")
        {
            int block_id;
            cin >> block_id;

#ifndef ONLINE_JUDGE
cout << "erase, idi = " << block_id << endl;
#endif
            int erased = 0;

            for (int i = 1; i <= m; ++i)
                if (mem[i] == block_id)
                {
                    ++erased;
                    mem[i] = 0;
                }

            if (erased == 0)
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
        } else
        {
#ifndef ONLINE_JUDGE
cout << "defrag" << endl;
#endif
            int free_block = m + 1, pos = 1;

            while (pos <= m)
            {
                if (mem[pos] == 0)
                {
                    free_block = min(free_block, pos);
                    ++pos;
                } else if (free_block <= m)
                {
                    int block_id = mem[pos];

                    while (mem[pos] == block_id)
                    {
                        mem[free_block++] = mem[pos];
                        mem[pos] = 0;
                        ++pos;
                    }

                    free_block = (mem[pos] == 0 ? pos : m + 1);
                } else
                    ++pos;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>

using namespace std;
using ii = pair<int, int>;

#define MAX 1100

int mem[MAX];
int id = 0;

int main()
{
    memset(mem, 0, sizeof mem);

    int t, m;
    cin >> t >> m;

    while (t--)
    {
        string cmd;
        cin >> cmd;

#ifndef ONLINE_JUDGE
printf("mem = ");
for (int i = 1; i <= m; ++i)
printf("%d%c", mem[i], " \n"[i == m]);
#endif
        if (cmd == "alloc")
        {
            int size;
            cin >> size;

#ifndef ONLINE_JUDGE
cout << "alloc, size = " << size << endl;
#endif
            int block = 0, pos = 0;

            for (int i = 1; i <= m; ++i)
            {
                if (mem[i] == 0)
                    ++block;
                else
                    block = 0;

                if (block == size)
                {
                    pos = i - block + 1;
                    break;
                }
            }

#ifndef ONLINE_JUDGE
cout << "size = " << size << ", pos = " << pos << endl;
#endif
            if (block == size)
            {
                ++id;

                for (int i = 0; i < size; ++i)
                    mem[i + pos] = id;

                cout << id << endl;
            }
            else
                cout << "NULL" << endl;
        } else if (cmd == "erase")
        {
            int block_id;
            cin >> block_id;

#ifndef ONLINE_JUDGE
cout << "erase, id = " << block_id << endl;
#endif
            int erased = 0;

            for (int i = 1; i <= m; ++i)
                if (mem[i] == block_id)
                {
                    ++erased;
                    mem[i] = 0;
                }

            if (erased == 0 or block_id <= 0)
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
        } else
        {
#ifndef ONLINE_JUDGE
cout << "defrag" << endl;
#endif
            int last = 0, count = 0;
            vector<ii> hs;

            for (int i = 1; i <= m + 1; ++i)
            {
                if (mem[i] == last)
                    ++count;
                else
                {
                    if (count > 0 and last > 0)
                        hs.push_back(ii(last, count));

                    count = 1;
                    last = mem[i];
                }
            }

            int pos = 1;

            for (auto p : hs)
            {
                for (int i = 0; i < p.second; ++i)
                    mem[pos++] = p.first;
            }

            while (pos <= m)
                mem[pos++] = 0;
        }
    }

    return 0;
}


import java.io.*;
import java.util.*;
public class Solution
{
    static long gcd;
    static long x,y;
    public static void main(String ag[])
    {
        Scanner sc=new Scanner(System.in);

        long A=sc.nextLong();
        long B=sc.nextLong();
        long C=sc.nextLong();
        gcd(A,B);
        if(C%gcd!=0)
        System.out.println(-1);
        else
        {
            C*=-1;
            x*=C/gcd;
            y*=C/gcd;
            System.out.println(x+" "+y);
        }

    }
    public static void gcd(long A,long B)
    {
        if(B==0)
        {
            x=1;
            y=0;
            gcd=A;
        }
        else
        {
            gcd(B,A%B);
            long temp=x;
            x=y;
            y=temp-(A/B)*y;
        }
    }
}


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

public class hello {
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException  e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
	public static FastReader sc = new FastReader();
	public static void take_array(long arr[], int size) {
		for (int i = 0; i < size; i++) {
			arr[i] = sc.nextLong();
		}
	}
	public static void print_arr(long arr[]) {
		for (long x : arr)
			System.out.print(x + " ");
	}
	public static String[] convert_String_to_arr(String s) {
		String arr[] = new String[s.length()];
		for (int i = 0; i < s.length(); i++) {
			arr[i] = String.valueOf(s.charAt(i));
		}
		return arr;
	}
	public static void take_prefix_array(long arr[], int size, long []prefix) {
		long temp = 0;
		for (int i = 0; i < size; i++) {
			temp += arr[i];
			prefix[i] = temp;
		}
	}
	public static void print(Object c, int a) {
		if (a == -1)
			System.out.print(c + " ");
		else
			System.out.println(c);
	}
	public static void space() {
		System.out.println();
	}
	public static long sum_array(long arr[]) {
		long sum = 0;
		for (long x : arr)
			sum += x;
		return sum;
	}
	public static void swap(long a, long b) {
		long temp = a;
		a = b;
		b = temp;
	}
	public static long min(long a, long b, long c) {
		return Math.min(a, Math.min(b, c));
	}
	public static long max(long a, long b, long c) {
		return Math.max(a, Math.max(b, c));
	}
	public static long gcd(long a, long b) {
		if (a < b)swap(a, b);
		if (b == 0)return a;
		return gcd(b, a % b);
	}
	public static long sol(long a, long b) {
		if (b == 0) {
			x = 1; y = 0;
			return a;
		}
		long res = sol(b, a % b);
		long t = x;
		x = y;
		y = (t - (a / b) * y);
		return res;
	}
	public static long x, y;
	public static void main(String []args) {
		long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong();
		long g = sol(a, b);
		if (c % g != 0)
			print(-1, 0);
		else {
			long k = (-c) / g;
			print(k * x + " " + k * y, 0);
		}
	}
}


import java.util.*;
public class Line {

    static long[] solution(long a, long b){
        if(a==0) return new long[]{0,1,b};
        long[] ans = solution(b%a,a);
        return new long[]{ans[1]-(b/a)*ans[0],ans[0],ans[2]};
    }

    static void solve(){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long[] ans = solution(a,b);
        long C = -c/ans[2];
        if((c%ans[2])==0) System.out.println((C*ans[0])+" "+(C*ans[1]));
        else System.out.println(-1);
    }

    public static void main(String args[]) {
        solve();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class Main{
	public static StreamTokenizer sc=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
	public static int nextint() throws IOException {
		sc.nextToken();
		return (int)sc.nval;
	}
	public static String nextLine() throws IOException{
		sc.nextToken();
		return sc.sval;
	}
	public static int gcd(int a,int b) {
		if(b==0) {
			return a;
		}else {
			return gcd(b,a%b);
		}
	}
	public static int extgcd(int a,int b,Long x,Long y) {
		int d=a;
		if(b==0) {
			x.v=1;
			y.v=0;
		}else {
			d=extgcd(b,a%b,y,x);
			y.v-=(a/b)*x.v;
		}
		return d;
	}
	static class Long{
		long v;
	}
	public static void main(String args[]) throws IOException {
		PrintWriter out=new PrintWriter(System.out);
		int a=nextint();
		int b=nextint();
		int c=nextint();
		Long x = new Long(),y=new Long();
		int k=extgcd(a,b,x,y);
		if((-c)%k!=0) {
			out.print(-1);
		}else {
			out.print((-c)/k*x.v+" "+(-c)/k*y.v);
		}
		out.flush();
		out.close();
	}
}


import java.io.*;
import java.util.*;
import java.math.*; // for bigInteger

public class practice {

    private final static int M = (int)1e9+7;

    private static final InputReader scan = new InputReader(System.in);
    private static final PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    private static final StringBuilder sb = new StringBuilder();

  	public static void main(String args[]) throws Exception {
        //scanner scan = new scanner(system.in);
        //scan.usedelimiter("");  // for reading character by character

        long a = scan.nextLong(), b = scan.nextLong(), c = -scan.nextLong();

        long rpp = a, rp = b, r = -1;
        long xpp = 1, xp = 0, x = -1;
        long ypp = 0, yp = 1, y = -1;

        while(r!=0) {
            long q = rpp/rp;
            r = rpp-rp*q;
            x = xpp-xp*q;
            y = ypp-yp*q;
            rpp = rp;
            rp = r;
            xpp = xp;
            xp = x;
            ypp = yp;
            yp = y;
        }

        long g = rpp;
        x = xpp*(c/g);
        y = ypp*(c/g);
        if(Math.abs(xpp)*Math.abs(c/g)<0)  x=Long.MAX_VALUE;
        if(Math.abs(ypp)*Math.abs(c/g)<0)  y=Long.MAX_VALUE;
        if(a<0)  x=-x;
        if(b<0)  y=-y;

        long left = (long)-5e18;
        long right = (long)5e18;

        if(c%g!=0) {
            out.println("NO");
        } else {
            if(left<=x && x<=right && left<=y && x<=right)
            out.println(x+" "+y);
            else
            out.println("NO");
        }

        scan.close();
        out.close();
    }

	private final static int m =(int)1e9+7;
	private static class Pair<T,V> {
		T first;
		V second;
		Pair(final T first, final V second) {
			this.first = first;
			this.second = second;
		}
		public boolean equals(Object o) {
			Pair given = (Pair)o;
			if(given.first == first && given.second == second)  return true;
			return false;
		}
		public int hashCode() {
			long temp = (long)(first.hashCode())*31;
			temp = (temp+(long)second.hashCode())%m;
			return (int)temp;
		}
	}

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;
        private SpaceCharFilter filter;

        public InputReader(final InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public String next() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }

        public void close() throws IOException {
            if(stream==null) {
                return;
            }
            stream.close();
        }
    }

    public static void debug(final int[] ...var) {
        for(final int[] row : var) {
            debug(row);
        }
    }

    public static void debug(final long[] ...var) {
        for(final long[] row : var) {
            debug(row);
        }
    }

    public static void debug(final String[] ...var) {
        for(final String[] row : var) {
            debug(row);
        }
    }

    public static void debug(final double[] ...var) {
        for(final double[] row : var) {
            debug(row);
        }
    }

    public static void debug(final char[] ...var) {
        for(final char[] row : var) {
            debug(row);
        }
    }

    public static void debug(final int ...var) {
        for(final int i:var)  System.err.print(i+" ");
        System.err.println();
    }
    public static void debug(final String ...var) {
        for(final String i:var)  System.err.print(i+" ");
        System.err.println();
    }
    public static void debug(final double ...var) {
        for(final double i:var)  System.err.print(i+" ");
        System.err.println();
    }

    public static void debug(final long ...var) {
        for(final long i:var)  System.err.print(i+" ");
        System.err.println();
    }

    public static void debug(final char ...var) {
        for(final char c:var)  System.err.print(c+" ");
        System.err.println();
    }

    /*
    public static <T> void debug(T ...varargs) {
        // Warning
        // Heap Pollution might occur
        // this overrides even 1d and 2d array methods as it is an object...
        // + i am not using object based array like Integer[]
        // I am using int[] so that is a problem as i need Wrapper class as an argument
        for(T val:varargs)  System.err.printf("%s ",val);
        System.err.println();
    }
    */
}


import java.io.*;
import java.util.*;
import java.math.*; // for bigInteger

public class practice {

    private final static int M = (int)1e9+7;

    private static final InputReader scan = new InputReader(System.in);
    private static final PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    private static final StringBuilder sb = new StringBuilder();

  	public static void main(String args[]) throws Exception {
        //scanner scan = new scanner(system.in);
        //scan.usedelimiter("");  // for reading character by character

        long a = scan.nextLong(), b = scan.nextLong(), c = -scan.nextLong();

        long rpp = a, rp = b, r = -1;
        long xpp = 1, xp = 0, x = -1;
        long ypp = 0, yp = 1, y = -1;

        while(r!=0) {
            long q = rpp/rp;
            r = rpp-rp*q;
            x = xpp-xp*q;
            y = ypp-yp*q;
            rpp = rp;
            rp = r;
            xpp = xp;
            xp = x;
            ypp = yp;
            yp = y;
        }

        long g = rpp;
        x = xpp*(c/g);
        y = ypp*(c/g);
        if(Math.abs(xpp)*Math.abs(c/g)<0)  x=Long.MAX_VALUE;
        if(Math.abs(ypp)*Math.abs(c/g)<0)  y=Long.MAX_VALUE;
        if(a<0)  x=-x;
        if(b<0)  y=-y;

        long left = (long)-5e18;
        long right = (long)5e18;

        if(c%g!=0) {
            out.println("-1");
        } else {
            if(left<=x && x<=right && left<=y && x<=right)
            out.println(x+" "+y);
            else
            out.println("-1");
        }

        scan.close();
        out.close();
    }

	private final static int m =(int)1e9+7;
	private static class Pair<T,V> {
		T first;
		V second;
		Pair(final T first, final V second) {
			this.first = first;
			this.second = second;
		}
		public boolean equals(Object o) {
			Pair given = (Pair)o;
			if(given.first == first && given.second == second)  return true;
			return false;
		}
		public int hashCode() {
			long temp = (long)(first.hashCode())*31;
			temp = (temp+(long)second.hashCode())%m;
			return (int)temp;
		}
	}

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;
        private SpaceCharFilter filter;

        public InputReader(final InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public String next() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }

        public void close() throws IOException {
            if(stream==null) {
                return;
            }
            stream.close();
        }
    }

    public static void debug(final int[] ...var) {
        for(final int[] row : var) {
            debug(row);
        }
    }

    public static void debug(final long[] ...var) {
        for(final long[] row : var) {
            debug(row);
        }
    }

    public static void debug(final String[] ...var) {
        for(final String[] row : var) {
            debug(row);
        }
    }

    public static void debug(final double[] ...var) {
        for(final double[] row : var) {
            debug(row);
        }
    }

    public static void debug(final char[] ...var) {
        for(final char[] row : var) {
            debug(row);
        }
    }

    public static void debug(final int ...var) {
        for(final int i:var)  System.err.print(i+" ");
        System.err.println();
    }
    public static void debug(final String ...var) {
        for(final String i:var)  System.err.print(i+" ");
        System.err.println();
    }
    public static void debug(final double ...var) {
        for(final double i:var)  System.err.print(i+" ");
        System.err.println();
    }

    public static void debug(final long ...var) {
        for(final long i:var)  System.err.print(i+" ");
        System.err.println();
    }

    public static void debug(final char ...var) {
        for(final char c:var)  System.err.print(c+" ");
        System.err.println();
    }

    /*
    public static <T> void debug(T ...varargs) {
        // Warning
        // Heap Pollution might occur
        // this overrides even 1d and 2d array methods as it is an object...
        // + i am not using object based array like Integer[]
        // I am using int[] so that is a problem as i need Wrapper class as an argument
        for(T val:varargs)  System.err.printf("%s ",val);
        System.err.println();
    }
    */
}