#include <bits/stdc++.h>
using namespace std;
struct task {
  int t, k, d, i, ans;
};
int main() {
  int n, m;
  cin >> n >> m;
  task arr[m];
  int servers[n + 1];
  for (int i = 1; i <= n; i++) servers[i] = 1;
  for (int i = 0; i < m; i++) {
    cin >> arr[i].t >> arr[i].k >> arr[i].d, arr[i].i = i;
  }
  for (int i = 0; i < m; i++) {
    int cnt = 0, sum = 0;
    for (int j = 1; j <= n && cnt != arr[i].k; j++) {
      if (servers[j] <= arr[i].t) {
        cnt++;
        sum += j;
      }
    }
    if (cnt == arr[i].k) {
      arr[i].ans = sum;
      for (int j = 1; j <= n && cnt; j++) {
        if (servers[j] <= arr[i].t) {
          cnt--;
          servers[j] = arr[i].t + arr[i].d;
        }
      }
    } else
      arr[i].ans = -1;
  }
  for (int i = 0; i < m; i++) {
    cout << arr[i].ans << endl;
  }
  return 0;
}
