#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int main() {     srand(1373737);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, t, k, d, q;     cin >> n >> q;     vector<int> arr(n);     for (int i = 0; i < (int)q; i++) {       cin >> t >> k >> d;       int free = 0;       for (int j = 0; j < (int)n; j++) {         if (arr[j] <= t) free++;       }       if (free < k) {         cout << -1 <<   n ;         continue;       }       int res = 0;       for (int j = 0; j < n && k; j++) {         if (arr[j] <= t) {           arr[j] = t + d;           k--;           res += j + 1;         }       }       cout << res <<   n ;     }     return 0;   }   