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.util.*;
import java.io.*;

public class ProblemC{
	static class Solver{
		int n, q;
		int[] a;
		Task[] t;
		int T = 1000000;

		public void solve(InputReader in, PrintWriter out) {
			n = in.nextInt();
			q = in.nextInt();
			a = new int[n];
			t = new Task[q];
		
			HashMap<Integer, Task> tasks = new HashMap<>();
			for (int i = 0; i < q; ++ i) {
				t[i] = new Task(in.nextInt(), in.nextInt(), in.nextInt(), i);
				tasks.put(t[i].time, t[i]);
			}

			Arrays.sort(t);
			
			for (int second = 1; second <= T; ++ second) {
				Task s = tasks.get(second);
				int free = 0;
				for (int i = 0; i < n; ++ i) {
					if (a[i] > 0) -- a[i];
					if (a[i] == 0) ++ free;		
				}

				if (s == null) continue;

				if (free < s.serv) {
					s.out = -1;
					// for (int i : a)
					// 	out.print(i + " ");
					// out.println();
					continue;
				}
				long sum = 0;
				for (int i = 0; i < n; ++ i) {
					if (s.serv == 0) break;
					if (a[i] == 0) {
						a[i] = s.dur;
						sum += (i+1);
						s.serv--;
					}
				}
				s.out = sum;
				// for (int i : a)
				// 	out.print(i + " ");
				// out.println();
			}

			Arrays.sort(t, new Comparator<Task>() {
				public int compare(Task a, Task b) {
					return Integer.compare(a.index, b.index);
				}
			});

			for (Task s : t)
				out.println(s.out);
		}

		static class Task implements Comparable<Task>{
			int time, serv, dur;
			int index;
			long out;
			public Task(int t, int k, int d, int i) {
				time = t;
				serv = k;
				dur = d;
				index = i;
			}

			public int compareTo(Task t) {
				return Integer.compare(time, t.time);
			}
		}
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Solver solver = new Solver();
		solver.solve(in, out);
		out.close();
	}

	static class InputReader{
		BufferedReader reader;
		StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
		}

		String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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