#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define MS0(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=6500100;
const int INF=(1<<29);
struct Node
{
int l,r;
int ms,ls,rs;
int tag;
int lch,rch;
};
struct SegTree
{
Node T[maxn];
int p,rt;
int newnode(int l,int r,int has)
{
T[++p]=(Node){l,r,(r-l+1)*has,(r-l+1)*has,(r-l+1)*has,has,-1,-1};
return p;
}
void init(int l,int r)
{
p=0;
rt=newnode(l,r,1);
}
void push_down(int rt)
{
if(T[rt].lch==-1&&T[rt].rch==-1) return;
if(T[rt].tag!=-1){
int lch=T[rt].lch,rch=T[rt].rch,tag=T[rt].tag;
T[lch].tag=T[rch].tag=tag;
T[lch].ms=T[lch].ls=T[lch].rs=tag*(T[lch].r-T[lch].l+1);
T[rch].ms=T[rch].ls=T[rch].rs=tag*(T[rch].r-T[rch].l+1);
T[rt].tag=-1;
}
}
void push_up(int rt)
{
int lch=T[rt].lch,rch=T[rt].rch;
T[rt].ls=T[lch].ls;
T[rt].rs=T[rch].rs;
if(T[rt].ls==T[lch].r-T[lch].l+1) T[rt].ls+=T[rch].ls;
if(T[rt].rs==T[rch].r-T[rch].l+1) T[rt].rs+=T[lch].rs;
T[rt].ms=max(max(T[lch].ms,T[rch].ms),T[lch].rs+T[rch].ls);
}
int query(int siz,int rt)
{
if(T[rt].ms<siz) return 0;
if(T[rt].ls>=siz) return T[rt].l;
push_down(rt);
int t=query(siz,T[rt].lch);
if(t) return t;
int m=(T[rt].l+T[rt].r)>>1;
if(T[T[rt].lch].rs+T[T[rt].rch].ls>=siz) return m-T[T[rt].lch].rs+1;
return query(siz,T[rt].rch);
}
void update(int L,int R,int c,int rt)
{
int l=T[rt].l,r=T[rt].r;
if(L<=l&&r<=R){
T[rt].ms=T[rt].ls=T[rt].rs=(r-l+1)*c;
T[rt].tag=c;
return;
}
int m=(l+r)>>1;
if(T[rt].lch==-1&&T[rt].rch==-1){
T[rt].lch=newnode(l,m,T[rt].tag);
T[rt].rch=newnode(m+1,r,T[rt].tag);
}
push_down(rt);
if(L<=m) update(L,R,c,T[rt].lch);
if(R>m) update(L,R,c,T[rt].rch);
push_up(rt);
}
};SegTree sgt;
int n,q;
char op[maxn];int x;
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
while(cin>>n>>q){
sgt.init(1,n);
while(q--){
scanf("%s",op);
if(op[0]==‘m‘){
sscanf(op,"malloc(%d)",&x);
int L=sgt.query(x,sgt.rt);
printf("%d\n",L);
if(L) sgt.update(L,L+x-1,0,sgt.rt);
}
else{
sscanf(op,"free(%d)",&x);
sgt.update(x,x,1,sgt.rt);
}
}
}
return 0;
}