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: #include <bits/stdc++.h>
  using namespace std;
  void solveA() {
    int n;
    cin >> n;
    vector<long double> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    long double ans = -2000000000.0;
    long double sum2 = 0;
    for (int i = 0; i < n; ++i) sum2 += a[i];
    long double sum1 = 0;
    for (int i = 0; i + 1 < n; ++i) {
      sum1 += a[i];
      sum2 -= a[i];
      ans = max(ans, sum1 / (i + 1) + sum2 / (n - i - 1));
    }
    cout << ans << "\n";
  }
  void solveB() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<int> b = a;
    sort(b.begin(), b.end());
    b.resize(unique(b.begin(), b.end()) - b.begin());
    for (int i = 0; i < n; ++i)
      a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
    int kol = 1;
    for (int i = 1; i < n; ++i)
      if (!((a[i] == a[i - 1] + 1))) ++kol;
    if (kol <= k)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  const int MOD = 1000000007;
  long long powmod(long long a, long long n) {
    long long ans = 1;
    while (n > 0) {
      if (n % 2 == 1) ans = (ans * a) % MOD;
      a = (a * a) % MOD;
      n /= 2;
    }
    return ans;
  }
  void solveC() {
    long long n, k;
    cin >> n >> k;
    if (k == 0) {
      cout << "1\n";
      return;
    }
    long long kolEq = powmod(2, n - 1);
    if (n % 2 == 0)
      --kolEq;
    else
      ++kolEq;
    if (kolEq < 0) kolEq += MOD;
    kolEq %= MOD;
    long long kolMore = (n % 2 == 0);
    long long z = powmod(2, n);
    z = powmod(z, k - 1);
    long long f = 1;
    for (int i = 1; i <= k; ++i) {
      f = kolEq * f + kolMore * powmod(2, n * (i - 1));
      f %= MOD;
    }
    cout << f << "\n";
  }
  struct Seg {
    int i, l, r;
  };
  bool operator<(Seg s1, Seg s2) { return s1.i < s2.i; }
  struct Node {
    int mx, pos;
    bool isAss;
    int assMx, assPos;
  };
  vector<Node> tree;
  void assignOnVertex(int v, int l, int r, pair<int, int> p) {
    tree[v].isAss = true;
    tree[v].mx = tree[v].assMx = p.first;
    tree[v].pos = tree[v].assPos = p.second;
  }
  void push(int v, int l, int r) {
    if (tree[v].isAss) {
      pair<int, int> p(tree[v].assMx, tree[v].assPos);
      int mid = (l + r) / 2;
      assignOnVertex(v * 2, l, mid, p);
      assignOnVertex(v * 2 + 1, mid + 1, r, p);
      tree[v].isAss = false;
    }
  }
  pair<int, int> findMax(int v, int l, int r, int ql, int qr) {
    if (r < ql || qr < l) return make_pair(-1, -1);
    if (ql <= l && r <= qr) return make_pair(tree[v].mx, tree[v].pos);
    push(v, l, r);
    int mid = (l + r) / 2;
    return max(findMax(v * 2, l, mid, ql, qr),
               findMax(v * 2 + 1, mid + 1, r, ql, qr));
  }
  pair<int, int> findMaxInTree(int l, int r) {
    return findMax(1, 0, tree.size() / 2 - 1, l, r);
  }
  void assign(int v, int l, int r, int ql, int qr, pair<int, int> qp) {
    if (r < ql || qr < l) return;
    if (ql <= l && r <= qr) {
      assignOnVertex(v, l, r, qp);
      return;
    }
    push(v, l, r);
    int mid = (l + r) / 2;
    assign(v * 2, l, mid, ql, qr, qp);
    assign(v * 2 + 1, mid + 1, r, ql, qr, qp);
    pair<int, int> p = max(make_pair(tree[2 * v].mx, tree[2 * v].pos),
                           make_pair(tree[2 * v + 1].mx, tree[2 * v + 1].pos));
    tree[v].mx = p.first;
    tree[v].pos = p.second;
  }
  void assignInTree(int l, int r, pair<int, int> pp) {
    assign(1, 0, tree.size() / 2 - 1, l, r, pp);
  }
  void solveD() {
    int n, m;
    cin >> n >> m;
    vector<Seg> ss(m);
    for (int i = 0; i < m; ++i) cin >> ss[i].i >> ss[i].l >> ss[i].r;
    vector<int> cs;
    for (int i = 0; i < m; ++i) {
      ss[i].i--;
      cs.push_back(ss[i].l);
      cs.push_back(ss[i].r);
    }
    sort(cs.begin(), cs.end());
    cs.resize(unique(cs.begin(), cs.end()) - cs.begin());
    for (int i = 0; i < m; ++i) {
      ss[i].l = lower_bound(cs.begin(), cs.end(), ss[i].l) - cs.begin();
      ss[i].r = lower_bound(cs.begin(), cs.end(), ss[i].r) - cs.begin();
    }
    sort(ss.begin(), ss.end());
    int deg = 1;
    while (deg < cs.size()) deg *= 2;
    tree.assign(deg * 2, Node{0, -1, false, -1, -1});
    vector<int> d(n, -1);
    vector<int> pr(n, -1);
    for (int i = 0; i < m;) {
      int ni = i;
      while (ni < m && ss[i].i == ss[ni].i) ++ni;
      pair<int, int> ans(-1, -1);
      for (int j = i; j < ni; ++j)
        ans = max(ans, findMaxInTree(ss[j].l, ss[j].r));
      d[ss[i].i] = ans.first + 1;
      pr[ss[i].i] = ans.second;
      for (int j = i; j < ni; ++j)
        assignInTree(ss[j].l, ss[j].r, make_pair(ans.first + 1, ss[i].i));
      i = ni;
    }
    int pos = max_element(d.begin(), d.end()) - d.begin();
    int ans = d[pos];
    vector<int> used(n, 0);
    for (; pos >= 0; pos = pr[pos]) used[pos] = 1;
    cout << n - ans << "\n";
    for (int i = 0; i < n; ++i)
      if (!used[i]) cout << i + 1 << ' ';
    cout << "\n";
  }
  int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    int test = 1;
    while (test--) solveD();
    return 0;
  }
  