///
#include <bits/stdc++.h>
using namespace std;
int n,q,t,k,d;
int Time[105],stmp,cnt;
int main()
{
// freopen("nhap.inp", "r", stdin);
cin>>n>>q;
for (int i=1; i <= q; i++)
{
scanf("%d %d %d",&t,&k,&d);
stmp=cnt=0;
for (int j=1; j<=n; j++)
{
if (Time[j]<=t)
{
stmp+=j;
Time[j]=t+d;
cnt++;
if (cnt==k) break;
}
}
if (cnt!=k) printf("-1\n");
else printf("%d\n",stmp);
}
return 0;
}
Ly8vCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG4scSx0LGssZDsKaW50IFRpbWVbMTA1XSxzdG1wLGNudDsKCmludCBtYWluKCkKewovLyAgICBmcmVvcGVuKCJuaGFwLmlucCIsICJyIiwgc3RkaW4pOwogICAgY2luPj5uPj5xOwogICAgZm9yIChpbnQgaT0xOyBpIDw9IHE7IGkrKykKICAgIHsKICAgICAgICBzY2FuZigiJWQgJWQgJWQiLCZ0LCZrLCZkKTsKICAgICAgICBzdG1wPWNudD0wOwogICAgICAgIGZvciAoaW50IGo9MTsgajw9bjsgaisrKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKFRpbWVbal08PXQpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHN0bXArPWo7CiAgICAgICAgICAgICAgICBUaW1lW2pdPXQrZDsKICAgICAgICAgICAgICAgIGNudCsrOwogICAgICAgICAgICAgICAgaWYgKGNudD09aykgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGNudCE9aykgcHJpbnRmKCItMVxuIik7CiAgICAgICAgZWxzZSBwcmludGYoIiVkXG4iLHN0bXApOwogICAgfQogICAgcmV0dXJuIDA7Cn0=