#include <bits/stdc++.h>
using namespace std;
int vis[105];
int main() {
  int n, m, a, b, c;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    int f = 0;
    int cont = 0;
    int num = 0;
    for (int j = 1; j <= n; j++) {
      if (vis[j] <= a) {
        cont++;
      }
    }
    if (cont >= b) {
      for (int j = 1; j <= n; j++) {
        if (vis[j] <= a) {
          b--;
          vis[j] = a + c;
          num += j;
        }
        if (b == 0) break;
      }
      printf("%d\n", num);
    } else
      printf("-1\n");
  }
  return 0;
}
