#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int64_t, pair<int64_t, int64_t>> a,
          pair<int64_t, pair<int64_t, int64_t>> b) {
  return a.second.second < b.second.second;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t n, q, li, ri, xi;
  cin >> n >> q;
  int64_t f[n + 1];
  memset(f, 0, sizeof(f));
  vector<pair<int64_t, pair<int64_t, int64_t>>> arr;
  for (int64_t i = 1; i <= q; i++) {
    cin >> li >> ri >> xi;
    arr.push_back({xi, {li, ri}});
  }
  sort(arr.begin(), arr.end(), comp);
  for (int64_t i = 0; i < q; i++) {
    for (int64_t j = n; j > arr[i].first; j--) {
      if (f[j - arr[i].first] >= arr[i].second.first)
        f[j] = max(f[j], f[j - arr[i].first]);
    }
    f[arr[i].first] = max(f[arr[i].first], arr[i].second.second);
  }
  int64_t cnt = 0;
  for (int64_t i = 0; i <= n; i++) {
    if (f[i] > 0) cnt++;
  }
  cout << cnt << endl;
  for (int64_t i = 0; i <= n; i++)
    if (f[i]) cout << i << " ";
  cout << endl;
}
