#include <bits/stdc++.h>
using namespace std;
using bset = bitset<10016>;
int main() {
  int n, q;
  cin >> n >> q;
  vector<vector<int>> tree(2 * n);
  for (int i = 0; i < q; ++i) {
    int l, r, x;
    cin >> l >> r >> x;
    for (l += n - 1, r += n; l < r; l /= 2, r /= 2) {
      if (l & 1) tree[l++].push_back(x);
      if (r & 1) tree[--r].push_back(x);
    }
  }
  bset sol;
  function<void(int, bset)> go = [&](int node, bset curr) {
    for (int x : tree[node]) {
      curr |= curr << x;
    }
    if (node >= n) {
      sol |= curr;
    } else {
      go(2 * node, curr);
      go(2 * node + 1, curr);
    }
  };
  for (int l = n, r = 2 * n; l < r; l /= 2, r /= 2) {
    if (l & 1) go(l++, 1);
    if (r & 1) go(--r, 1);
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) cnt += sol[i];
  cout << cnt << '\n';
  for (int i = 1; i <= n; ++i)
    if (sol[i]) cout << i << ' ';
}
