#include <bits/stdc++.h>
using namespace std;
long long int arr[1000001];
string str;
int main() {
  ios::sync_with_stdio(false);
  cin.clear();
  long long int t, n, i, j, ans = 0, count = 0, sum = 0, k, s, q;
  cin >> n >> q;
  while (q--) {
    cin >> s >> k >> t;
    count = 0;
    for (i = 1; i <= n; i++) {
      if (arr[i] == 0 || arr[i] < s) count++;
    }
    if (count < k) {
      cout << -1 << endl;
    } else {
      i = 1;
      ans = 0;
      while (k) {
        if (arr[i] == 0 || arr[i] < s) {
          arr[i] = s + t - 1;
          ans += i;
          k--;
        }
        i++;
      }
      cout << ans << endl;
    }
  }
}
