#include <bits/stdc++.h>
using namespace std;
int n, k, a, b, c, x, y, i, j, m[105];
int main() {
  cin >> n >> k;
  while (i < k) {
    cin >> a >> b >> c;
    while (x < b && j < n) {
      if (m[j] <= a || m[j] == 0) m[j] = 0, x++;
      j++;
    }
    j = 0;
    if (x < b)
      x = 0, cout << -1 << endl, 0;
    else {
      while (x > 0) {
        if (m[j] == 0) x--, y += j + 1, m[j] = a + c;
        j++;
      }
      cout << y << endl, y = 0, j = 0;
    }
    i++;
  }
}
