#include <bits/stdc++.h>
using namespace std;
const long long N = 1e+6, oo = 1e+18, M = (1e+9) + 7;
int n, m, t, k, d;
int main() {
  scanf("%d%d", &n, &m);
  vector<int> v, time(n + 1);
  for (int i = 0; i < m; ++i) {
    int ans = 0;
    v.clear();
    scanf("%d%d%d", &t, &k, &d);
    for (int j = 1; j < n + 1; ++j) {
      if (time[j] < t) v.push_back(j);
    }
    if (v.size() < k) {
      printf("%d\n", -1);
      continue;
    }
    for (int j = 0; j < v.size(); ++j) {
      ans += v[j];
      time[v[j]] = t + d - 1;
      if (j + 1 == k) break;
    }
    printf("%d\n", ans);
  }
  return 0;
}
