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: import java.io.*;
  import java.lang.reflect.Array;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Scanner;
  
  public class main {
      static class Reader {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public Reader()
          {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public Reader(String file_name) throws IOException
          {
              din = new DataInputStream(
                      new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public String readLine() throws IOException
          {
              byte[] buf = new byte[64]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n') {
                      if (cnt != 0) {
                          break;
                      }
                      else {
                          continue;
                      }
                  }
                  buf[cnt++] = (byte)c;
              }
              return new String(buf, 0, cnt);
          }
  
          public int nextInt() throws IOException
          {
              int ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          public long nextLong() throws IOException
          {
              long ret = 0;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg)
                  return -ret;
              return ret;
          }
  
          public double nextDouble() throws IOException
          {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
  
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          private void fillBuffer() throws IOException
          {
              bytesRead = din.read(buffer, bufferPointer = 0,
                      BUFFER_SIZE);
              if (bytesRead == -1)
                  buffer[0] = -1;
          }
  
          private byte read() throws IOException
          {
              if (bufferPointer == bytesRead)
                  fillBuffer();
              return buffer[bufferPointer++];
          }
  
          public void close() throws IOException
          {
              if (din == null)
                  return;
              din.close();
          
          }
      }
      public static void main(String[] args) throws Exception{
          Reader in = new Reader();
          BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
          int n = in.nextInt();
          int m = in.nextInt();
          //long time = System.currentTimeMillis();
          ArrayList<ArrayList<ArrayList<Integer>>> rows = new ArrayList<>();
          for(int i = 0; i < n; i++){
              rows.add(new ArrayList<>());
          }
          for(int i = 0; i < m; i++){
              int index = in.nextInt() - 1;
              int l = in.nextInt() - 1;
              int r = in.nextInt() - 1;
              ArrayList<Integer> segment = new ArrayList<>();
              segment.add(l);
              segment.add(r);
              rows.get(index).add(segment);
          }
          ///if(n == 300000) System.out.println(System.currentTimeMillis() - time);
          RangeTree tree = new RangeTree(1000000000);
          int[] rowValues = new int[n];
          int maxVal = -1;
          int maxValIndex = -1;
          RangeTree.Node best;
          for(int i = 0; i < n; i++){
              best = null;
              for(ArrayList<Integer> segment:rows.get(i)){
                  RangeTree.Node cur = tree.getValue(segment.get(0),segment.get(1)+1,tree.root);
                  if(best == null || cur.value > best.value){
                      best = cur;
                  }
              }
              if(best == null) continue;
              rowValues[i] = best.index;
              if(best.value + 1 > maxVal || maxVal == -1){
                  maxVal = best.value + 1;
                  maxValIndex = i;
              }
              int bestVal = best.value;
              for(ArrayList<Integer> segment:rows.get(i)){
                  tree.add(segment.get(0),segment.get(1)+1,bestVal+1,i,tree.root);
              }
          }
          out.write((n - maxVal) + "\n");
          HashSet<Integer> toRemove = new HashSet<>();
          for(int i = 0; i < n; i++){
              toRemove.add(i);
          }
          while(maxValIndex != -1){
              toRemove.remove(maxValIndex);
              maxValIndex = rowValues[maxValIndex];
          }
          int i = 1;
          for(Integer remove:toRemove){
              out.write((remove + 1) + "");
              if(i == toRemove.size()) continue;
              out.write(" ");
          }
          out.write("\n");
          out.flush();
      }
  
      static class RangeTree{
          class Node{
              public int min;
              public int max;
              public int value = 0;
              public int index = -1;
              public Node left = null;
              public Node right = null;
  
              public Node(int min, int max){
                  this.min = min;
                  this.max = max;
              }
          }
          public Node root;
  
          public RangeTree(int n){
              int i = 1;
              while(i < n){
                  i *= 2;
              }
              root = new Node(0,i);
          }
  
          void populate(Node current, int lastIndex,int lastVal){
              int l = current.min;
              int r = current.max;
              if(l + 1 == r) return;
              int m = (l+r)/2;
              current.left = new Node(l,m);
              current.right = new Node(m,r);
              current.left.value = lastVal;
              current.right.value = lastVal;
              current.left.index = lastIndex;
              current.right.index = lastIndex;
          }
  
          public void add(int l, int r, int amount, int index, Node current){
              int lastVal = current.value;
              int lastIndex = current.index;
              if(current.value < amount){
                  current.value = amount;
                  current.index = index;
                  if(current.min >= l && current.max <= r){
                      current.left = null;
                      current.right = null;
                      return;
                  }
              } else if (current.left == null) return;
              if(current.left == null){
                  populate(current,lastIndex,lastVal);
              }
              if(current.right.min > l){
                  add(l,r,amount,index,current.left);
              }
              if(current.right.min < r){
                  add(l,r,amount,index,current.right);
              }
          }
  
          public Node getValue(int l, int r, Node current){
              if((current.min >= l && current.max <= r) || current.left == null) return current;
              Node left = null;
              Node right = null;
              if(current.right.min > l){
                  left = getValue(l,r,current.left);
              }
              if(current.right.min < r){
                  right = getValue(l,r,current.right);
              }
              return right == null || (left != null && left.value > right.value) ? left:right;
          }
  
          public long getValue(int index){
              long value = 0;
              Node current = root;
              while(true){
                  value += current.value;
                  if(current.min + 1 == current.max) return value;
                  if(current.right.min <= index){
                      current = current.right;
                      continue;
                  }
                  current = current.left;
              }
          }
      }
  }
  