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 long long mod = 1e9 + 7;
  const long long inf = 1e9 + 7;
  const double eps = 1e-9;
  struct segtree {
    int n;
    pair<int, int> t[2400005], lz[2400005];
    const pair<int, int> neutral = {0, -1};
    void init(int n) {
      this->n = n;
      fill(t + 1, t + 4 * n + 5, neutral);
      fill(lz + 1, lz + 4 * n + 5, neutral);
    }
    pair<int, int> comb(pair<int, int> u, pair<int, int> v) { return max(u, v); }
    void pull(int u) { t[u] = comb(t[2 * u], t[2 * u + 1]); }
    void push(int u, int tl, int tr) {
      if (lz[u] != neutral) {
        t[u] = max(t[u], lz[u]);
        if (tl != tr) {
          lz[2 * u] = max(lz[2 * u], lz[u]);
          lz[2 * u + 1] = max(lz[2 * u + 1], lz[u]);
        }
        lz[u] = neutral;
      }
    }
    void upd(int u, int tl, int tr, int l, int r, pair<int, int> val) {
      push(u, tl, tr);
      if (l > r)
        return;
      else if (l == tl && r == tr) {
        lz[u] = max(lz[u], val);
        push(u, tl, tr);
      } else {
        int tm = (tl + tr) / 2;
        upd(2 * u, tl, tm, l, min(r, tm), val);
        upd(2 * u + 1, tm + 1, tr, max(l, tm + 1), r, val);
        pull(u);
      }
    }
    void upd(int l, int r, pair<int, int> val) { upd(1, 1, n, l, r, val); }
    pair<int, int> query(int u, int tl, int tr, int l, int r) {
      if (l > r) return neutral;
      push(u, tl, tr);
      if (l == tl && r == tr)
        return t[u];
      else {
        int tm = (tl + tr) / 2;
        return comb(query(2 * u, tl, tm, l, min(r, tm)),
                    query(2 * u + 1, tm + 1, tr, max(l, tm + 1), r));
      }
    }
    pair<int, int> query(int l, int r) { return query(1, 1, n, l, r); }
  } ds;
  int n, m;
  vector<pair<int, int> > r[300005];
  vector<int> comp;
  int p[300005];
  bool vis[300005];
  int ans, cur;
  inline int compress(int x) {
    return upper_bound(comp.begin(), comp.end(), x) - comp.begin();
  }
  void solve() {
    cin >> n >> m;
    for (int i = 1, row, le, ri; i <= m; ++i) {
      cin >> row >> le >> ri;
      r[row].push_back({le, ri});
      comp.push_back(le);
      comp.push_back(ri);
    }
    sort(comp.begin(), comp.end());
    comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
    for (int i = 1; i <= n; ++i)
      for (auto &x : r[i]) x = {compress(x.first), compress(x.second)};
    ds.init(comp.size());
    for (int i = 1; i <= n; ++i) {
      pair<int, int> mx = {0, -1};
      for (auto x : r[i]) mx = max(mx, ds.query(x.first, x.second));
      p[i] = mx.second;
      for (auto x : r[i]) ds.upd(x.first, x.second, {mx.first + 1, i});
    }
    tie(ans, cur) = ds.query(1, comp.size());
    memset(vis, 0, sizeof(vis));
    for (; cur != -1; cur = p[cur]) vis[cur] = 1;
    cout << n - ans << "\n";
    for (int i = 1; i <= n; ++i)
      if (!vis[i]) cout << i << " ";
  }
  signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int test = 1;
    for (int tc = 1; tc <= test; ++tc) solve();
    return 0;
  }
  