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;
  const int N = 6e5 + 7;
  long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
  long long exgcd(long long a, long long b, long long& x, long long& y) {
    if (b == 0) {
      x = 1, y = 0;
      return a;
    } else {
      long long r = exgcd(b, a % b, x, y), t = x;
      x = y;
      y = t - a / b * x;
      return r;
    }
  }
  int tr[N * 4], pos[N * 4], tag[N * 4], tag2[N * 4];
  inline int lc(int x) { return x << 1; }
  inline int rc(int x) { return x << 1 | 1; }
  void pu(int t) {
    tr[t] = tr[lc(t)];
    pos[t] = pos[lc(t)];
    if (tr[t] < tr[rc(t)]) {
      tr[t] = tr[rc(t)];
      pos[t] = pos[rc(t)];
    }
  }
  void pd(int t) {
    if (tag[t] > tr[lc(t)]) {
      tr[lc(t)] = tag[t];
      pos[lc(t)] = tag2[t];
    }
    if (tag[t] > tr[rc(t)]) {
      tr[rc(t)] = tag[t];
      pos[rc(t)] = tag2[t];
    }
    if (tag[t] > tag[lc(t)]) {
      tag[lc(t)] = tag[t];
      tag2[lc(t)] = tag2[t];
    }
    if (tag[t] > tag[rc(t)]) {
      tag[rc(t)] = tag[t];
      tag2[rc(t)] = tag2[t];
    }
    tag[t] = 0;
  }
  pair<int, int> query(int t, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) {
      return make_pair(tr[t], pos[t]);
    } else {
      pair<int, int> res = make_pair(0, 0);
      int m = l + r >> 1;
      pd(t);
      if (ql <= m) {
        pair<int, int> p = query(lc(t), l, m, ql, qr);
        if (p.first > res.first) res = p;
      }
      if (qr > m) {
        pair<int, int> p = query(rc(t), m + 1, r, ql, qr);
        if (p.first > res.first) res = p;
      }
      pu(t);
      return res;
    }
  }
  void upd(int t, int l, int r, int ql, int qr, int x, int id) {
    if (ql <= l && r <= qr) {
      if (x > tag[t]) {
        tag[t] = x;
        tag2[t] = id;
      }
      if (x > tr[t]) {
        tr[t] = x;
        pos[t] = id;
      }
      return;
    } else {
      int m = l + r >> 1;
      pd(t);
      if (ql <= m) upd(lc(t), l, m, ql, qr, x, id);
      if (qr > m) upd(rc(t), m + 1, r, ql, qr, x, id);
      pu(t);
    }
  }
  vector<pair<int, int> > g[N];
  vector<pair<int, pair<int, int> > > d;
  vector<int> alls;
  int bp[N];
  int gt(int x) {
    return lower_bound(alls.begin(), alls.end(), x) - alls.begin() + 1;
  }
  int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
      int id, l, r;
      cin >> id >> l >> r;
      d.push_back(make_pair(id, make_pair(l, r)));
    }
    sort(d.begin(), d.end());
    for (int i = 0; i < m; i++) {
      int id, l, r;
      id = d[i].first, l = d[i].second.first, r = d[i].second.second;
      if (g[id].size() == 0 || g[id].back().second + 1 < l)
        g[id].push_back(make_pair(l, r));
      else
        g[id].back().second = max(g[id].back().second, r);
      alls.push_back(l), alls.push_back(r);
    }
    sort(alls.begin(), alls.end());
    alls.erase(unique(alls.begin(), alls.end()), alls.end());
    int w = alls.size();
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < g[i].size(); j++) {
        g[i][j].first = gt(g[i][j].first);
        g[i][j].second = gt(g[i][j].second);
      }
    }
    pair<int, int> ans = make_pair(0, 0);
    set<int> st;
    for (int i = 1; i <= n; i++) {
      st.insert(i);
      pair<int, int> res2 = make_pair(0, 0);
      for (int j = 0; j < g[i].size(); j++) {
        int l = g[i][j].first, r = g[i][j].second;
        pair<int, int> res = query(1, 1, w, l, r);
        res.first += 1;
        if (res.first > res2.first) res2 = res;
      }
      bp[i] = res2.second;
      for (int j = 0; j < g[i].size(); j++) {
        int l = g[i][j].first, r = g[i][j].second;
        upd(1, 1, w, l, r, res2.first, i);
      }
      if (res2.first > ans.first) ans = res2, ans.second = i;
    }
    while (ans.second) {
      st.erase(ans.second);
      ans.second = bp[ans.second];
    }
    cout << st.size() << '\n';
    for (auto x : st) {
      cout << x << ' ';
    }
  }
  