100 1
1000000 100 1000
 5 3
1 4 10
2 2 5
3 1 6
 10 4
1 5 20
2 5 200
100 6 20
101 1 100
 5 3
1 3 4
4 3 4
6 4 1
 4 1
6 1 1
 8 6
1 3 20
4 2 1
6 6 5
9 1 1
15 3 6
21 8 8
 4 5
1 2 3
2 1 3
3 1 2
4 3 3
5 4 1
 8 4
1 3 2
2 3 100
10 6 20
11 5 20
 4 10
1 1 1
3 1 2
4 1 2
6 1 2
8 1 2
13 1 2
16 1 1
17 1 2
19 3 1
20 1 1
 5 3
1 4 4
4 2 2
5 5 2
 4 3
1 3 10
2 2 15
12 4 1
 5 4
1 1 4
2 4 4
5 2 20
11 5 2
 1 10
4 1 1
9 1 1
10 1 1
12 1 1
13 1 1
15 1 1
16 1 1
18 1 1
19 1 1
20 1 1

5050
 10
-1
5
 15
40
-1
1
 6
-1
10
 1
 6
9
-1
4
15
36
 3
3
4
-1
10
 6
15
-1
21
 1
1
2
1
1
1
1
1
6
1
 10
-1
15
 6
-1
10
 1
14
-1
15
 1
1
1
1
1
1
1
1
1
1

import java.io.*;
import java.text.DecimalFormat;
import java.util.*;

public class CF_747C {
	public static void main(String[] args) {
		new CF_747C().run();
	}
	public void run(){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		Task[] a = new Task[q];
		int max = Integer.MIN_VALUE;
		for(int i = 0;i<q;i++){
			int comeTime = sc.nextInt();
			int sevNum = sc.nextInt();
			int second = sc.nextInt();
			a[i] = new Task(comeTime, sevNum, second);
		}
		Arrays.sort(a);
		TreeSet<Integer> sev = new TreeSet<>();
		TreeMap<Integer,ArrayList<Integer>> end = new TreeMap<>();
		for(int i = 0;i<n;i++)
			sev.add(i+1);
		int index = 0;
		for(int i = 1;i<=a[q-1].comtTime;i++){
			if(!end.isEmpty() && i==end.firstKey()){
				sev.addAll(end.get(i));
				end.remove(i);
			}
			if(a[index].comtTime==i){
				int sum = 0;
				if(a[index].serverNum>sev.size()){
					out.println(-1);
					index++;
					continue;
				}
				ArrayList<Integer> serComsum = new ArrayList<Integer>();
				for(int j = 0;j<a[index].serverNum;j++){
					int tmp = sev.pollFirst();
					serComsum.add(tmp);
					sum+=tmp;
				}
				out.println(sum);
				if(end.containsKey(i+a[index].second)){
					ArrayList<Integer> tmp = end.get(i+a[index].second);
					tmp.addAll(serComsum);
					end.put(i+a[index].second, tmp);
				}else{
					end.put(i+a[index].second,serComsum);
				}
				index++;
			}
		}
		out.close();
	}
}
class Task implements Comparable<Task>{
	int comtTime;
	int serverNum;
	int second;
	
	public Task(int comtTime, int serverNum, int second) {
		this.comtTime = comtTime;
		this.serverNum = serverNum;
		this.second = second;
	}

	@Override
	public int compareTo(Task o) {
		return this.comtTime-o.comtTime;
	}
	
	
}
class FastScanner {
	public BufferedReader br;
	public StringTokenizer st;

	public FastScanner(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public boolean hasMoreTokens() {
		while (st == null || !st.hasMoreTokens()) {
			String line = null;
			try {
				line = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (line == null)
				return false;
			st = new StringTokenizer(line);
		}
		return true;
	}

	public String next() {
		if (!hasMoreTokens())
			return null;
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	//读一个int类型的数组
	public int[] readIntArray(int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = nextInt();
		}
		return array;
	}

	//读一个long数组
	public long[] readLongArray(int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = nextLong();
		}
		return array;
	}

	//读一个字符串数组
	public String[] readStringArray(int n) {
		String[] a = new String[n];
		for (int i = 0; i < n; i++) {
			a[i] = next();
		}
		return a;
	}

	//打乱一个数组，便于排序
	public void shuffleIntArray(int[] a) {
		Random rand = new Random();
		for (int i = 0; i < a.length; i++) {
			int x = rand.nextInt(i + 1); // 0~i
			int t = a[i];
			a[i] = a[x];
			a[x] = t;
		}
	}

	// 只适合比较小的数，太大的数会越界
	public long factorial(long n) {
		if (n == 0)
			return 1L;
		long res = 1;
		for (long i = 2; i <= n; i++) {
			res *= i;
		}
		return res;
	}

	// 只适合比较小的数，太大的数会越界
	public long combination(long mom, long son) {
		return factorial(mom) / (factorial(son) * factorial(mom - son));
	}

	//求最小公倍数
	public long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	//求最大公约数
	public long lcm(long a, long b) {
		return a * b / (gcd(a, b));
	}

	//格式化double类型的数
	public double format(String pattern, double d) {
		DecimalFormat df = new DecimalFormat(pattern);
		return Double.parseDouble(df.format(d));
	}

	//判断一个数是否是2的指数
	public boolean isPowerOfTwo(long v) {
		return (v & (v - 1)) == 0;
	}
	
}
