description: Moamen was drawing a grid of n rows and 10^9 columns containing only digits 0 and 1. Ezzat noticed what Moamen was drawing and became interested in the minimum number of rows one needs to remove to make the grid beautiful.
  
  A grid is beautiful if and only if for every two consecutive rows there is at least one column containing 1 in these two rows.
  
  Ezzat will give you the number of rows n, and m segments of the grid that contain digits 1. Every segment is represented with three integers i, l, and r, where i represents the row number, and l and r represent the first and the last column of the segment in that row.
  
  For example, if n = 3, m = 6, and the segments are (1,1,1), (1,7,8), (2,7,7), (2,15,15), (3,1,1), (3,15,15), then the grid is:
  
  <image>
  
  Your task is to tell Ezzat the minimum number of rows that should be removed to make the grid beautiful.
  
  Input
  
  The first line contains two integers n and m (1 ≤ n, m ≤ 3⋅10^5).
  
  Each of the next m lines contains three integers i, l, and r (1 ≤ i ≤ n, 1 ≤ l ≤ r ≤ 10^9). Each of these m lines means that row number i contains digits 1 in columns from l to r, inclusive.
  
  Note that the segments may overlap.
  
  Output
  
  In the first line, print a single integer k — the minimum number of rows that should be removed.
  
  In the second line print k distinct integers r_1, r_2, …, r_k, representing the rows that should be removed (1 ≤ r_i ≤ n), in any order.
  
  If there are multiple answers, print any.
  
  Examples
  
  Input
  
  
  3 6
  1 1 1
  1 7 8
  2 7 7
  2 15 15
  3 1 1
  3 15 15
  
  
  Output
  
  
  0
  
  
  Input
  
  
  5 4
  1 2 3
  2 4 6
  3 3 5
  5 1 1
  
  
  Output
  
  
  3
  2 4 5
  
  Note
  
  In the first test case, the grid is the one explained in the problem statement. The grid has the following properties: 
  
    1. The 1-st row and the 2-nd row have a common 1 in the column 7. 
    2. The 2-nd row and the 3-rd row have a common 1 in the column 15. 
  
  As a result, this grid is beautiful and we do not need to remove any row.
  
  In the second test case, the given grid is as follows: 
  
  <image>
solution: // coached by rainboy
  import java.io.*;
  import java.util.*;
  
  public class CF1557D extends PrintWriter {
  	CF1557D() { super(System.out); }
  	static class Scanner {
  		Scanner(InputStream in) { this.in = in; } InputStream in;
  		byte[] bb = new byte[1 << 15]; int i, n;
  		byte getc() {
  			if (i == n) {
  				i = n = 0;
  				try { n = in.read(bb); } catch (IOException e) {}
  			}
  			return i < n ? bb[i++] : 0;
  		}
  		int nextInt() {
  			byte c = 0; while (c <= ' ') c = getc();
  			int a = 0; while (c > ' ') { a = a * 10 + c - '0'; c = getc(); }
  			return a;
  		}
  	}
  	Scanner sc = new Scanner(System.in);
  	public static void main(String[] $) {
  		CF1557D o = new CF1557D(); o.main(); o.flush();
  	}
  
  	long[] st, lz; int k_, n_;
  	void init(int n) {
  		k_ = 0;
  		while (1 << k_ < n)
  			k_++;
  		n_ = 1 << k_;
  		st = new long[n_ * 2];
  		lz = new long[n_];
  	}
  	void put(int i, long a) {
  		if (i < n_)
  			lz[i] = Math.max(lz[i], a);
  		st[i] = Math.max(st[i], a);
  	}
  	void pus(int i) {
  		if (lz[i] > 0) {
  			put(i << 1, lz[i]);
  			put(i << 1 | 1, lz[i]);
  			lz[i] = 0;
  		}
  	}
  	void pul(int i) {
  		if (lz[i] == 0)
  			st[i] = Math.max(st[i << 1], st[i << 1 | 1]);
  	}
  	void push(int i) {
  		for (int h = k_; h > 0; h--)
  			pus(i >> h);
  	}
  	void pull(int i) {
  		while (i > 1)
  			pul(i >>= 1);
  	}
  	long query(int l, int r) {
  		int l_ = l += n_, r_ = r += n_;
  		push(l_); push(r_);
  		long a = 0;
  		for ( ; l <= r; l >>= 1, r >>= 1) {
  			if ((l & 1) == 1)
  				a = Math.max(a, st[l++]);
  			if ((r & 1) == 0)
  				a = Math.max(a, st[r--]);
  		}
  		return a;
  	}
  	void update(int l, int r, long a) {
  		int l_ = l += n_, r_ = r += n_;
  		push(l_); push(r_);
  		for ( ; l <= r; l >>= 1, r >>= 1) {
  			if ((l & 1) == 1)
  				put(l++, a);
  			if ((r & 1) == 0)
  				put(r--, a);
  		}
  		pull(l_); pull(r_);
  	}
  	void main() {
  		int n = sc.nextInt();
  		int m = sc.nextInt();
  		int[] ii = new int[m];
  		int[] xx = new int[m * 2];
  		for (int h = 0; h < m; h++) {
  			ii[h] = sc.nextInt();
  			xx[h << 1] = sc.nextInt();
  			xx[h << 1 | 1] = sc.nextInt();
  		}
  		int[] hh = new int[m * 2];
  		for (int h = 0; h < m * 2; h++)
  			hh[h] = h;
  		hh = Arrays.stream(hh).boxed().sorted((h1, h2) -> xx[h1] - xx[h2]).mapToInt($->$).toArray();
  		int x = 0;
  		for (int h = 0; h < m * 2; h++)
  			xx[hh[h]] = h + 1 == m * 2 || xx[hh[h]] != xx[hh[h + 1]] ? x++ : x;
  		init(x);
  		for (int h = 0; h < m; h++)
  			hh[h] = h;
  		hh = Arrays.stream(hh, 0, m).boxed().sorted((h1, h2) -> ii[h1] - ii[h2]).mapToInt($->$).toArray();
  		int[] pp = new int[n + 1];
  		int[] dp = new int[n + 1];
  		for (int i = 1, h = 0; i <= n; i++) {
  			long w = 0;
  			int h_ = h;
  			while (h_ < m && ii[hh[h_]] == i) {
  				int g = hh[h_++];
  				w = Math.max(w, query(xx[g << 1], xx[g << 1 | 1]));
  			}
  			pp[i] = (int) (w & (1 << 30) - 1);
  			if (h < h_) {
  				dp[i] = dp[pp[i]] + 1;
  				while (h < h_) {
  					int g = hh[h++];
  					update(xx[g << 1], xx[g << 1 | 1], (long) dp[i] << 30 | i);
  				}
  			}
  		}
  		int ans = 0, i_ = 0;
  		for (int i = 1; i <= n; i++)
  			if (ans < dp[i]) {
  				ans = dp[i];
  				i_ = i;
  			}
  		boolean[] used = new boolean[n + 1];
  		while (i_ > 0) {
  			used[i_] = true;
  			i_ = pp[i_];
  		}
  		println(n - ans);
  		for (int i = 1; i <= n; i++)
  			if (!used[i])
  				print(i + " ");
  		println();
  	}
  }
  