#include <bits/stdc++.h>
using namespace std;
long long x, y, z, us[110000], n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    long long cnt = 0, ans = 0;
    for (int j = 1; j <= n; j++) {
      if (us[j] <= x) cnt++;
    }
    if (cnt < y) {
      cout << -1 << '\n';
      continue;
    }
    cnt = 0;
    for (int j = 1; j <= n; j++) {
      if (us[j] <= x) {
        us[j] = x + z;
        cnt++;
        ans += j;
      }
      if (cnt == y) {
        break;
      }
    }
    if (cnt < y) {
      cout << -1 << '\n';
    } else {
      cout << ans << '\n';
    }
  }
  return 0;
}
