#include <bits/stdc++.h>
using namespace std;
int N, Q;
int buf[100];
int main() {
  cin >> N >> Q;
  for (int _Q = 0; _Q < Q; _Q++) {
    int t, k, d;
    scanf("%d %d %d", &t, &k, &d);
    int cnt = 0;
    for (int i = 0; i < N; i++)
      if (buf[i] < t) cnt++;
    if (cnt < k) {
      printf("-1\n");
      continue;
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
      if (buf[i] < t && 0 < k) {
        buf[i] = t + d - 1;
        k--;
        ans += i + 1;
      }
    printf("%d\n", ans);
  }
}
