#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int q;
  cin >> q;
  int** problems = new int*[q];
  for (int i = 0; i < q; i++) {
    int* prob = new int[3];
    problems[i] = prob;
  }
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> problems[i][j];
    }
  }
  int* servers = new int[n]{0};
  for (int i = 0; i < q; i++) {
    int number = 0;
    for (int k = 0; k < n; k++) {
      if (servers[k] <= problems[i][0]) {
        number++;
      }
    }
    if (number < problems[i][1]) {
      cout << -1 << endl;
    } else {
      int serversum = 0;
      for (int ser = 0; ser < problems[i][1]; ser++) {
        for (int j = 0; j < n; j++) {
          if (servers[j] <= problems[i][0]) {
            servers[j] = problems[i][0] + problems[i][2];
            serversum += (j + 1);
            break;
          }
        }
      }
      cout << serversum << endl;
    }
  }
  return 0;
}
