#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
const int P = 998244353;
struct edge {
  int u, v, len;
  inline edge() {}
  inline edge(int _u, int _v, int _len) {
    u = _u;
    v = _v;
    len = _len;
  }
} a[N], Q[N], res[N];
struct node {
  int l, r;
  vector<int> E;
  node *lson, *rson;
} pool[3 * N], *root;
int n, m;
int OscarDaGumert;
int top = -1;
int Index, cnt;
bitset<N> cur;
bitset<N> ans;
void B_T(node *now, int l, int r) {
  now->l = l;
  now->r = r;
  if (l == r) return;
  int lr = (l + r) >> 1, rl = lr + 1;
  now->lson = &pool[++top];
  B_T(now->lson, l, lr);
  now->rson = &pool[++top];
  B_T(now->rson, rl, r);
}
void change(node *now, int l, int r, int id) {
  if (now->l == l && now->r == r) {
    now->E.push_back(a[id].len);
    return;
  }
  int lr = (now->l + now->r) >> 1, rl = lr + 1;
  if (r < rl)
    change(now->lson, l, r, id);
  else if (l > lr)
    change(now->rson, l, r, id);
  else {
    change(now->lson, l, lr, id);
    change(now->rson, rl, r, id);
  }
}
inline void query(node *now) {
  bitset<N> tmp = cur;
  int len = now->E.size();
  for (int i = 0; i < len; i++) {
    cur |= (cur << now->E[i]);
  }
  ans |= cur;
  if (now->l != now->r) {
    query(now->lson);
    query(now->rson);
  }
  cur = tmp;
}
void init() {
  int x1, x2, x3;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x1, &x2, &x3);
    a[i] = edge(x1, x2, x3);
  }
  root = &pool[++top];
  B_T(root, 1, n);
  for (int i = 1; i <= m; i++) change(root, a[i].u, a[i].v, i);
  cur[0] = 1;
  query(root);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (ans[i] == 1) {
      cnt++;
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++) {
    if (ans[i] == 1) {
      printf("%d ", i);
    }
  }
}
int main(int argc, char **argv) {
  init();
  return 0;
}
