#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  int t, k, d;
  int c, v;
  int s[100] = {};
  scanf("%d%d", &n, &q);
  while (0 < q--) {
    scanf("%d%d%d", &t, &k, &d);
    c = 0;
    for (int i(0); i < n; ++i) c += s[i] <= t;
    if (k <= c) {
      c = v = 0;
      for (int i(0); i < n && c < k; ++i) {
        if (t < s[i]) continue;
        s[i] = t + d;
        ++c, v += i + 1;
      }
    } else {
      v = -1;
    }
    printf("%d\n", v);
  }
  return 0;
}
