#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int OO = 1e18;
const int md = 1e9 + 7;
int X[] = {0, 0, 1, -1}, Y[] = {1, -1, 0, 0};
void fast() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int dp[int(1e4 + 4)], t = 0, x, y, z, n, q, g[int(1e4 + 4)], res;
pair<P, int> p[int(1e4 + 4)];
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++)
    scanf("%d%d%d", &p[i].first.first, &p[i].first.second, &p[i].second);
  sort(p, p + q);
  memset(dp, -1, sizeof dp);
  memset(g, -1, sizeof g);
  dp[0] = g[0] = n;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j <= n; j++) {
      g[j] = max(g[j], dp[j]);
      if (dp[j] >= p[i].first.first && j + p[i].second <= n)
        g[j + p[i].second] =
            max(dp[j + p[i].second], min(dp[j], p[i].first.second));
    }
    g[p[i].second] = max(g[p[i].second], p[i].first.second);
    swap(dp, g);
  }
  for (int i = 1; i <= n; i++)
    if (dp[i] != -1) res++;
  printf("%d\n", res);
  for (int i = 1; i <= n; i++)
    if (dp[i] != -1) printf("%d ", i);
  printf("\n");
  return 0;
}
