#include <bits/stdc++.h>
using namespace std;
const int N = 10110;
struct Query {
  int l, r, x;
} quer[N];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    heapQuer;
int DP[N];
bool valid[N];
int n, nQ, ans = 0;
bool comp(Query u, Query v) { return u.l < v.l; }
int main() {
  scanf("%d%d", &n, &nQ);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d%d", &quer[i].l, &quer[i].r, &quer[i].x);
  sort(quer + 1, quer + nQ + 1, comp);
  memset(DP, 0, sizeof(DP));
  memset(valid, 0, sizeof(valid));
  DP[0] = 1;
  for (int i = 1; i <= nQ; i++) {
    while (heapQuer.size() && heapQuer.top().first < quer[i].l) {
      int v = heapQuer.top().second;
      heapQuer.pop();
      for (int k = v; k <= n; ++k) DP[k] -= DP[k - v];
    }
    for (int k = n; k >= quer[i].x; --k) {
      DP[k] += DP[k - quer[i].x];
      valid[k] |= DP[k];
    }
    heapQuer.push(pair<int, int>(quer[i].r, quer[i].x));
  }
  for (int i = 1; i <= n; ++i) ans += valid[i];
  printf("%d\n", ans);
  for (int i = 1; i <= n; ++i)
    if (valid[i]) printf("%d ", i);
}
