#include <bits/stdc++.h>
using namespace std;
int _gcd(int a, int b) { return b == 0 ? a : _gcd(b, a % b); }
int phi(int n) {
  int ret = n;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) {
        n /= i;
      }
      ret -= ret / i;
    }
  }
  if (n > 1) ret -= ret / n;
  return ret;
}
int a[] = {10, 20, 30, 40, 50, 60, 70, 80};
int binarysearch(int aa[], int key) {
  int begin = 0;
  int end = 7;
  int mid = 0;
  int index = -1;
  while (begin <= end) {
    mid = begin + end;
    mid /= 2;
    if (aa[mid] == key) {
      index = mid;
      break;
    } else if (aa[mid] < key)
      begin = mid + 1;
    else if (aa[mid] > key)
      end = mid - 1;
  }
  return index;
}
int x[] = {0, 1, 0, -1, -1, -1, 0, 1};
int y[] = {1, 1, 1, 1, 0, -1, -1, -1};
vector<int> v[30030];
map<int, int> m;
bool vis[30030];
bool prime(int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int main() {
  int n, q;
  while (cin >> n >> q) {
    int server[n], t, k, d, kk = 1;
    memset(server, 0, sizeof server);
    for (int i = 1; i <= q; i++) {
      cin >> t >> k >> d;
      int sum = 0;
      int currentavailable = 0;
      if (i == 1) {
        currentavailable = n;
        if (k > n)
          cout << "-1\n";
        else {
          kk = t;
          for (int j = 0; j < k; j++) {
            if (server[j] == 0) {
              server[j] = d;
              sum += j + 1;
            }
          }
          cout << sum << endl;
        }
      } else {
        for (int j = 0; j < n; j++) {
          int ss = server[j];
          if (server[j] > 0) {
            server[j] -= abs(t - kk);
            if (server[j] < 0) server[j] = 0;
          }
        }
        for (int i = 0; i < n; i++) {
          if (server[i] == 0) currentavailable++;
        }
        if (currentavailable >= k) {
          for (int j = 0, l = 0; j < n and l < k; j++) {
            if (server[j] == 0) {
              server[j] = d;
              sum += j + 1;
              l++;
            }
          }
          cout << sum << endl;
        } else
          cout << "-1\n";
        kk = t;
      }
    }
  }
  return 0;
}
