#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) cnt++;
if (cnt<k) { printf("-1\n"); continue; }
cnt=0;
for (int j=1; j<=n; j++)
{
if (Time[j]<=t)
{
stmp+=j;
Time[j]=t+d;
cnt++;
if (cnt==k) break;
}
}
printf("%d\n",stmp);
}
return 0;
}
CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmludCBuLHEsdCxrLGQ7CmludCBUaW1lWzEwNV0sc3RtcCxjbnQ7CiAKaW50IG1haW4oKQp7Ci8vICAgIGZyZW9wZW4oIm5oYXAuaW5wIiwgInIiLCBzdGRpbik7CiAgICBjaW4+Pm4+PnE7CiAgICBmb3IgKGludCBpPTE7IGkgPD0gcTsgaSsrKQogICAgewogICAgICAgIHNjYW5mKCIlZCAlZCAlZCIsJnQsJmssJmQpOwogICAgICAgIHN0bXA9Y250PTA7CiAgICAgICAgZm9yIChpbnQgaj0xOyBqPD1uOyBqKyspCiAgICAgICAgICAgIGlmIChUaW1lW2pdPD10KSBjbnQrKzsKICAgICAgICBpZiAoY250PGspIHsgcHJpbnRmKCItMVxuIik7IGNvbnRpbnVlOyB9CiAgICAgICAgY250PTA7CiAgICAgICAgZm9yIChpbnQgaj0xOyBqPD1uOyBqKyspCiAgICAgICAgewogICAgICAgICAgICBpZiAoVGltZVtqXTw9dCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc3RtcCs9ajsKICAgICAgICAgICAgICAgIFRpbWVbal09dCtkOwogICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgICAgICBpZiAoY250PT1rKSBicmVhazsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBwcmludGYoIiVkXG4iLHN0bXApOwogICAgfQogICAgcmV0dXJuIDA7Cn0=