#include<bits/stdc++.h>
// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
// Including tree_order_statistics_node_update
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define LL long long
#define ULL unsigned long long
LL INF=10000000000000001LL;
#define PI 2.0*acos(0.0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//typedef tree<
//int,
//null_type,
//less<int>,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define clr(x,y) 	memset(x,y,sizeof (x) )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
//#define lc			tree[idx*2]
//#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
//LL X[4]={0,0,1,-1};
//LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

bool Check(int N,int pos){return (bool)(N & (1<<pos));} // check bit
int Set(int N,int pos){	return N=N | (1<<pos);}// set bit

const LL mod=2091573227LL;
LL modMul(LL a, LL b){

//	return (a%mod * b%mod)%mod;
    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b){
	if(b==0)return 1%mod;
	LL x=powerMod(a,b/2);
	x = (x%mod*x%mod)%mod;
//	x = modMul( x,x )%mod;
	if(b%2==1){
		x = (x%mod*a%mod)%mod;
//		x = modMul(x,a)%mod;
	}
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
const int mx = 100003;
//-------------------------------------------------------------------------------

int last[10005];
struct node{
	int l,r,x;
};
vector<node> Q;

bool cmp(node a,node b){
	if(a.l==b.l)return a.r<b.r;
	return a.l<b.l;
}

int main(){
//  READ;
//  WRITE;
	BOOST;
    int t,m,n,k,u,v;
	cin>>n;
	cin>>m;
	node nd;
	FOR(i,m){
		cin>>u>>v>>k;
		nd.l = u,nd.r = v,nd.x = k;
		Q.pb(nd);
	}
	sort(Q.begin(),Q.end(),cmp);
	clr(last,0);
	last[0]=n+1;
	bool vis[10004];
    FOR(i,m){
		FOR(j,n+2)vis[j] = 0;
        for(int j=0;j<=n;j++){
            if(last[j]>=Q[i].l){
				if( j+Q[i].x <= n ){
                    vis[ j+Q[i].x ] = 1;
				}
            }
        }
		for(int j=0;j<=n;j++){
			if(vis[j]){
				last[j] = Q[i].r;
			}
		}
    }
    k=0;
    for(int i=1;i<=n;i++)if(last[i])k++;
    cout<<k<<endl;
    for(int i=1;i<=n;i++)if(last[i])cout<<i<<" ";NL;

    return 0;
}


#include<bits/stdc++.h>
// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
// Including tree_order_statistics_node_update
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define LL long long
#define ULL unsigned long long
LL INF=10000000000000001LL;
#define PI 2.0*acos(0.0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//typedef tree<
//int,
//null_type,
//less<int>,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define clr(x,y) 	memset(x,y,sizeof (x) )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
//#define lc			tree[idx*2]
//#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
//LL X[4]={0,0,1,-1};
//LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

bool Check(int N,int pos){return (bool)(N & (1<<pos));} // check bit
int Set(int N,int pos){	return N=N | (1<<pos);}// set bit

const LL mod=2091573227LL;
LL modMul(LL a, LL b){

//	return (a%mod * b%mod)%mod;
    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b){
	if(b==0)return 1%mod;
	LL x=powerMod(a,b/2);
	x = (x%mod*x%mod)%mod;
//	x = modMul( x,x )%mod;
	if(b%2==1){
		x = (x%mod*a%mod)%mod;
//		x = modMul(x,a)%mod;
	}
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
const int mx = 100003;
//-------------------------------------------------------------------------------

int last[10005];
struct node{
	int l,r,x;
};
vector<node> Q;

bool cmp(node a,node b){
//	if(a.l==b.l)return a.r<b.r;
	return a.l<b.l;
}

int main(){
//  READ;
//  WRITE;
	BOOST;
    int t,m,n,k,u,v;
	cin>>n;
	cin>>m;
	node nd;
	FOR(i,m){
		cin>>u>>v>>k;
		nd.l = u,nd.r = v,nd.x = k;
		Q.pb(nd);
	}
	sort(Q.begin(),Q.end(),cmp);
	clr(last,0);
	last[0]=n;
	bool vis[10004];
	FOR(i,m){
		FOR(j,n+2)vis[j] = 0;
        for(int j=0;j<=n;j++){
			if(vis[j])continue;
            if(last[j]>=Q[i].l){
				if( j+Q[i].x <= n ){
                    vis[ j+Q[i].x ] = 1;
				}
            }
        }
		for(int j=0;j<=n;j++){
			if(vis[j]){
				last[j] = max(last[j],Q[i].r);
			}
		}
    }
    k=0;
    for(int i=1;i<=n;i++)if(last[i])k++;
    cout<<k<<endl;
    for(int i=1;i<=n;i++)if(last[i])cout<<i<<" ";NL;

    return 0;
}


#include<bits/stdc++.h>
// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
// Including tree_order_statistics_node_update
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define LL long long
#define ULL unsigned long long
LL INF=10000000000000001LL;
#define PI 2.0*acos(0.0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//typedef tree<
//int,
//null_type,
//less<int>,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define clr(x,y) 	memset(x,y,sizeof (x) )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,1,-1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

bool Check(int N,int pos){return (bool)(N & (1<<pos));} // check bit
int Set(int N,int pos){	return N=N | (1<<pos);}// set bit

const LL mod=2091573227LL;
LL modMul(LL a, LL b){

//	return (a%mod * b%mod)%mod;
    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b){
	if(b==0)return 1%mod;
	LL x=powerMod(a,b/2);
	x = (x%mod*x%mod)%mod;
//	x = modMul( x,x )%mod;
	if(b%2==1){
		x = (x%mod*a%mod)%mod;
//		x = modMul(x,a)%mod;
	}
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
const LL mx = 10009;
//-------------------------------------------------------------------------------

int pos[mx];
int r[mx];
bool vis[mx];
struct query{
	int l,r,x;
};
vector<query> arr;
bool cmp(query a,query b){return a.l<b.l;}
int main(){
//  READ;
//  WRITE;
//	BOOST;
    int t,c=0;
    int n,k,v,q,l,rr;
	query qr;
    cin>>n>>q;
    FOR(i,q){
		cin>>l>>rr>>v;
		qr.l=l,qr.r=rr,qr.x=v;
		arr.pb(qr);
    }

    sort(arr.begin(),arr.end(),cmp);
    pos[0] = 1;
    r[0] = n+1;
    FOR(j,q){
		qr = arr[j];
		clr(vis,0);
		r[qr.x] = max(r[qr.x],qr.r);
		for(int i=0;i<=n;i++){
//			cout<<i<<" "<<r[i]<<"  "<<qr.x<<endl;
			if( vis[i] )continue;
			vis[i] = 1;
			if( pos[i]==0 )continue;
            if( r[i]>=qr.l ){
                v = qr.x+i;
//                cout<<v<<endl;
				if(v<=n)pos[v]=1,vis[v]=1;
//				r[v] = max(r[v],)
            }
		}
//		ch;
    }
    c=0;
    for(int i=1;i<=n;i++)if(pos[i])c++;
    cout<<c<<endl;
    for(int i=1;i<=n;i++)if(pos[i])cout<<i<<" ";NL;

    return 0;
}


#include<bits/stdc++.h>
// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
// Including tree_order_statistics_node_update
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define LL long long
#define ULL unsigned long long
LL INF=10000000000000001LL;
#define PI 2.0*acos(0.0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//typedef tree<
//int,
//null_type,
//less<int>,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define clr(x,y) 	memset(x,y,sizeof (x) )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
//#define lc			tree[idx*2]
//#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
//LL X[4]={0,0,1,-1};
//LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

bool Check(int N,int pos){return (bool)(N & (1<<pos));} // check bit
int Set(int N,int pos){	return N=N | (1<<pos);}// set bit

const LL mod=2091573227LL;
LL modMul(LL a, LL b){

//	return (a%mod * b%mod)%mod;
    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b){
	if(b==0)return 1%mod;
	LL x=powerMod(a,b/2);
	x = (x%mod*x%mod)%mod;
//	x = modMul( x,x )%mod;
	if(b%2==1){
		x = (x%mod*a%mod)%mod;
//		x = modMul(x,a)%mod;
	}
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
const int mx = 100003;
//-------------------------------------------------------------------------------

int last[10005];
struct node{
	int l,r,x;
};
vector<node> Q;

bool cmp(node a,node b){
//	if(a.l==b.l)return a.r<b.r;
	return a.l<b.l;
}

int main(){
//  READ;
//  WRITE;
	BOOST;
    int t,m,n,k,u,v;
	cin>>n;
	cin>>m;
	node nd;
	FOR(i,m){
		cin>>u>>v>>k;
		nd.l = u,nd.r = v,nd.x = k;
		Q.pb(nd);
	}
	sort(Q.begin(),Q.end(),cmp);
	clr(last,0);
	last[0]=n;
	bool vis[10004];
    FOR(i,m){
		FOR(j,n+2)vis[j] = 0;
        for(int j=0;j<=n;j++){
            if(last[j]>=Q[i].l){
				if( j+Q[i].x <= n ){
                    vis[ j+Q[i].x ] = 1;
				}
            }
        }
		for(int j=0;j<=n;j++){
			if(vis[j]){
				last[j] = max(last[j],Q[i].r);
			}
		}
    }
    k=0;
    for(int i=1;i<=n;i++)if(last[i])k++;
    cout<<k<<endl;
    for(int i=1;i<=n;i++)if(last[i])cout<<i<<" ";NL;

    return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<short,short> ii;
typedef pair<ii,short> iii;

vector<int> ans;
vector<iii> vec;
vector<ii> bisa[10003];

bool comp(iii a, iii b)
{
	if(a.se != b.se) return a.se < b.se;
	else return a.fi < b.fi;
}

int main()
{

	// freopen("input.in", "r", stdin);
	int n, q; scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		vec.push_back({{x,y},z});

	}

	bisa[0].push_back({1,n});
	for(iii i : vec)
	{
		int x = i.fi.fi, y = i.fi.se;
		for(int j = n-i.se; j >= 0; j--)
		{
			for(auto it : bisa[j])
			{
				if(x > it.se || y < it.fi) continue;
				else bisa[j+i.se].push_back({max(x,it.fi),min(y,it.se)});
			}
		}
		// printf("%d %d %d\n", x, y, i.se);
	}
	for(int i = 1; i <= n; i++)
		if(bisa[i].size())
			ans.push_back(i);

	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<short,short> ii;

const long MOD1 = 1e9+7, MOD2 = 1e9+9;

int n, q;
vector<ii> vec;
vector<int> ans;
bool tot[10003];
long dp1[10003], dp2[10003];

int main()
{

	// freopen("input.in", "r", stdin);

	scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		vec.push_back({x,z});
		vec.push_back({y+1,-z});
	}
	sort(vec.begin(), vec.end());
	dp1[0] = dp2[0] = 1;
	for(auto i : vec)
	{
		if(i.se > 0)
		{
			for(int j = n-i.se; j >= 0; j--)
			{
				dp1[j+i.se] += dp1[j];
				dp1[j+i.se] %= MOD1;
				if(dp1[j+i.se])
					tot[j+i.se] = 1;
			}
		}
		else
		{
			i.se *= -1;
			for(int j = 0; j <= n-i.se; j++)
			{
				dp1[j+i.se] -= dp1[j];
				dp1[j+i.se] %= MOD1;
			}
		}
	}
	for(int i = 1; i <= n; i++)
		if(tot[i])
			ans.push_back(i);

	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<short,short> ii;

const long MOD1 = 1e9+7, MOD2 = 1e9+9;

int n, q;
vector<ii> vec;
vector<int> ans;
bool tot[10003];
long dp1[10003], dp2[10003];

int main()
{

	// freopen("input.in", "r", stdin);

	scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		vec.push_back({x,z});
		vec.push_back({y+1,-z});
	}
	sort(vec.begin(), vec.end());
	dp1[0] = dp2[0] = 1;
	for(auto i : vec)
	{
		if(i.se > 0)
		{
			for(int j = n-i.se; j >= 0; j--)
			{
				dp1[j+i.se] += dp1[j];
				dp1[j+i.se] %= MOD1;
			}
		}
		else
		{
			i.se *= -1;
			for(int j = 0; j <= n-i.se; j++)
			{
				dp1[j+i.se] -= dp1[j];
				dp1[j+i.se] %= MOD1;
			}
		}
		for(int i = 1;  i <= n; i++)
			if(dp1[i]%MOD1)
				tot[i] = 1;
	}
	for(int i = 1; i <= n; i++)
		if(tot[i])
			ans.push_back(i);

	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

vector<int> ans;
vector<iii> vec;
vector<ii> bisa[10003];

bool comp(iii a, iii b)
{
	if(a.se != b.se) return a.se < b.se;
	else return a.fi < b.fi;
}

int main()
{

	// freopen("input.in", "r", stdin);
	int n, q; scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		vec.push_back({{x,y},z});

	}

	bisa[0].push_back({1,n});
	for(iii i : vec)
	{
		int x = i.fi.fi, y = i.fi.se;
		for(int j = n-i.se; j >= 0; j--)
		{
			for(auto it : bisa[j])
			{
				if(x > it.se || y < it.fi) continue;
				else bisa[j+i.se].push_back({max(x,it.fi),min(y,it.se)});
			}
		}
		// printf("%d %d %d\n", x, y, i.se);
	}
	for(int i = 1; i <= n; i++)
		if(bisa[i].size())
			ans.push_back(i);

	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<short,short> ii;
typedef pair<ii,short> iii;

vector<int> ans;
vector<iii> vec;
vector<ii> bisa[10003];

bool comp(iii a, iii b)
{
	if(a.se != b.se) return a.se < b.se;
	else return a.fi < b.fi;
}

int main()
{

	// freopen("input.in", "r", stdin);
	int n, q; scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		vec.push_back({{x,y},z});

	}

	bisa[0].push_back({1,n});
	for(iii i : vec)
	{
		short x = i.fi.fi, y = i.fi.se;
		for(int j = n-i.se; j >= 0; j--)
		{
			for(auto it : bisa[j])
			{
				if(x > it.se || y < it.fi) continue;
				else bisa[j+i.se].push_back({max(x,it.fi),min(y,it.se)});
			}
		}
		// printf("%d %d %d\n", x, y, i.se);
	}
	for(int i = 1; i <= n; i++)
		if(bisa[i].size())
			ans.push_back(i);

	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<short,short> ii;

const long MOD1 = 1e9+7, MOD2 = 1e9+9;

int n, q;
vector<ii> vec;
vector<int> ans;
bool tot[10003];
long dp1[10003], dp2[10003];

int main()
{

	// freopen("input.in", "r", stdin);

	scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		vec.push_back({x,z});
		vec.push_back({y+1,-z});
	}

	dp1[0] = dp2[0] = 1;
	for(auto i : vec)
	{
		if(i.se > 0)
		{
			for(int j = n-i.se; j >= 0; j--)
			{
				dp1[j+i.se] += dp1[j];
				dp1[j+i.se] %= MOD1;
				dp2[j+i.se] += dp2[j];
				dp2[j+i.se] %= MOD2;
			}
		}
		else
		{
			i.se *= -1;
			for(int j = 0; j <= n-i.se; j++)
			{
				dp1[j+i.se] -= dp1[j];
				dp1[j+i.se] %= MOD1;
				dp1[j+i.se] -= dp2[j];
				dp1[j+i.se] %= MOD2;
			}
		}
		for(int i = 1;  i <= n; i++)
			if(dp1[i]%MOD1 || dp2[i]%MOD2)
				tot[i] = 1;
	}
	for(int i = 1; i <= n; i++)
		if(tot[i])
			ans.push_back(i);

	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

vector<int> ans;
vector<iii> vec;
vector<ii> inv, upd;
bool bisa[10003], tot[10003];

int main()
{

	// freopen("input.in", "r", stdin);
	int n, q; scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		vec.push_back({{x,y},z});
		upd.push_back({x,1});
		upd.push_back({y+1,-1});
	}
	sort(upd.begin(), upd.end());
	int cnt = 0;
	int kir = 0;
	for(int i = 0; i < upd.size(); i++)
	{
		if(cnt == 0)
		{
			kir = upd[i].fi;
			cnt += upd[i].se;
		}
		else
		{
			if(kir <= upd[i].fi-1) inv.push_back({kir,upd[i].fi-1});
			kir = upd[i].fi;
			cnt += upd[i].se;
		}
	}
	for(ii i : inv)
	{
		vector<int> num;
		for(iii j : vec)
		{
			if(j.fi.fi <= i.fi && i.se <= j.fi.se)
				num.push_back(j.se);
		}
		// printf("%d %d\n", i.fi, i.se);
		// printf("NUM : "); for(int j : num) printf("%d ", j); printf("\n");
		memset(bisa, 0, sizeof bisa);
		bisa[0] = 1;
		for(int j : num)
		{
			for(int k = n; k+j >= 0; k--)
			{
				bisa[k+j] = max(bisa[k+j],bisa[k]);
				if(bisa[k+j]) tot[k+j] = 1;
			}
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(tot[i])
			ans.push_back(i);
	}
	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<short,short> ii;
typedef pair<ii,short> iii;

int n;
bitset<10003> tree[40003];
vector<int> lazy[40003];
vector<int> ans;

void cek_lazy(int pos, int kir, int kan)
{
	while(lazy[pos].size())
	{
		int val = lazy[pos].back(); lazy[pos].pop_back();
		for(int i = n-val; i >= 0; i--)
			tree[pos][i+val] = max(tree[pos][i],tree[pos][i+val]);

		if(kir != kan)
		{
			lazy[pos*2+1].push_back(val);
			lazy[pos*2].push_back(val);
		}
	}
}

void update(int pos, int kir, int kan, int qkir , int qkan, int val)
{
	if(qkir <= kir && kan <= qkan)
	{
		for(int i = n-val; i >= 0; i--)
			tree[pos][i+val] = max(tree[pos][i],tree[pos][i+val]);

		// printf("POS %d %d %d\n", pos, kir, kan);
		// for(int i = 1; i <= n; i++)
		// {
		// 	printf("	%d %d\n", i, (int)tree[pos][i]);
		// }

		if(kir != kan)
		{
			lazy[pos*2+1].push_back(val);
			lazy[pos*2].push_back(val);
		}
	}
	else if(kir > qkan || qkir > kan) return;
	else
	{
		int mid = (kir+kan)/2;
		update(pos*2, kir, mid, qkir, qkan, val);
		update(pos*2+1, mid+1, kan, qkir, qkan, val);
		for(int i = 0; i <= n; i++)
			tree[pos][i] = max(tree[pos*2][i],tree[pos*2+1][i]);
	}
}

int main()
{

	// freopen("input.in", "r", stdin);

	for(int i = 1; i <= 40000; i++) tree[i][0] = 1;

	int q; scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		update(1, 1, n, x, y, z);
	}

	for(int i = 1; i <= n; i++)
		if(tree[1][i])
			ans.push_back(i);

	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

vector<int> ans;
vector<iii> vec;
vector<ii> inv, upd;
bool bisa[10003], tot[10003];

int main()
{

	freopen("input.in", "r", stdin);
	int n, q; scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		vec.push_back({{x,y},z});
		upd.push_back({x,1});
		upd.push_back({y+1,-1});
	}
	sort(upd.begin(), upd.end());
	int cnt = 0;
	int kir = 0;
	for(int i = 0; i < upd.size(); i++)
	{
		if(cnt == 0)
		{
			kir = upd[i].fi;
			cnt += upd[i].se;
		}
		else
		{
			if(kir <= upd[i].fi-1) inv.push_back({kir,upd[i].fi-1});
			kir = upd[i].fi;
			cnt += upd[i].se;
		}
	}
	for(ii i : inv)
	{
		vector<int> num;
		for(iii j : vec)
		{
			if(j.fi.fi <= i.fi && i.se <= j.fi.se)
				num.push_back(j.se);
		}
		// printf("%d %d\n", i.fi, i.se);
		// printf("NUM : "); for(int j : num) printf("%d ", j); printf("\n");
		memset(bisa, 0, sizeof bisa);
		bisa[0] = 1;
		for(int j : num)
		{
			for(int k = n; k+j >= 0; k--)
			{
				bisa[k+j] = max(bisa[k+j],bisa[k]);
				if(bisa[k+j]) tot[k+j] = 1;
			}
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(tot[i])
			ans.push_back(i);
	}
	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<short,short> ii;

const long MOD1 = 1e9+7, MOD2 = 1e9+9;

int n, q;
vector<ii> vec;
vector<int> ans;
bool tot[10003];
long dp1[10003], dp2[10003];

int main()
{

	// freopen("input.in", "r", stdin);

	scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		vec.push_back({x,z});
		vec.push_back({y+1,-z});
	}
	sort(vec.begin(), vec.end());
	dp1[0] = dp2[0] = 1;
	for(auto i : vec)
	{
		if(i.se > 0)
		{
			for(int j = n-i.se; j >= 0; j--)
			{
				dp1[j+i.se] += dp1[j];
				dp1[j+i.se] %= MOD1;
				dp2[j+i.se] += dp2[j];
				dp2[j+i.se] %= MOD2;
			}
		}
		else
		{
			i.se *= -1;
			for(int j = 0; j <= n-i.se; j++)
			{
				dp1[j+i.se] -= dp1[j];
				dp1[j+i.se] %= MOD1;
				dp2[j+i.se] -= dp2[j];
				dp2[j+i.se] %= MOD2;
			}
		}
		for(int i = 1;  i <= n; i++)
			if(dp1[i]%MOD1 || dp2[i]%MOD2)
				tot[i] = 1;
	}
	for(int i = 1; i <= n; i++)
		if(tot[i])
			ans.push_back(i);

	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<short,short> ii;

const long MOD1 = 1e9+7, MOD2 = 1e9+9;

int n, q;
vector<ii> vec;
vector<int> ans;
bool tot[10003];
long dp1[10003], dp2[10003];

int main()
{

	// freopen("input.in", "r", stdin);

	scanf("%d %d", &n, &q);
	while(q--)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		vec.push_back({x,z});
		vec.push_back({y+1,-z});
	}

	dp1[0] = dp2[0] = 1;
	for(auto i : vec)
	{
		if(i.se > 0)
		{
			for(int j = n-i.se; j >= 0; j--)
			{
				dp1[j+i.se] += dp1[j];
				dp1[j+i.se] %= MOD1;
				dp2[j+i.se] += dp2[j];
				dp2[j+i.se] %= MOD2;
			}
		}
		else
		{
			i.se *= -1;
			for(int j = 0; j <= n-i.se; j++)
			{
				dp1[j+i.se] -= dp1[j];
				dp1[j+i.se] %= MOD1;
				dp2[j+i.se] -= dp2[j];
				dp2[j+i.se] %= MOD2;
			}
		}
		for(int i = 1;  i <= n; i++)
			if(dp1[i]%MOD1 || dp2[i]%MOD2)
				tot[i] = 1;
	}
	for(int i = 1; i <= n; i++)
		if(tot[i])
			ans.push_back(i);

	printf("%d\n", (int)ans.size());
	for(int i = 0; i < ans.size(); i++)
	{
		printf("%d", ans[i]);
		if(i < ans.size()-1) printf(" ");
	} printf("\n");
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e4 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

int n, q;
bitset<maxn> dp[4 * maxn], ans;
vi seg[4 * maxn];

void update(int u, int l, int r, int b, int e, int val)
{
	if (b <= l && r <= e)
	{
		seg[u].pb(val);
		return;
	}
	int mid = (l + r) / 2;
	if (b < mid)
		update(lchild(u), l, mid, b, e, val);
	if (e > mid)
		update(rchild(u), mid, r, b, e, val);
}

void dfs(int u, int l, int r)
{
	for (int i : seg[u])
		dp[u] |= (dp[u] << i);
	if (r - l == 1)
	{
		ans |= dp[u];
		return;
	}
	int mid = (l + r) / 2;
	fori (i, 1, n + 1)
		if (dp[u][i])
		{
			dp[lchild(u)] |= dp[u];
			dp[rchild(u)] |= dp[u];
		}
	dfs(lchild(u), l, mid);
	dfs(rchild(u), mid, r);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fori (i, 0, maxn)
		dp[i][0] = true;

	cin >> n >> q;
	int l, r, x;
	fori (i, 0, q)
	{
		cin >> l >> r >> x;
		update(0, 0, n, l - 1, r, x);
	}
	dfs(0, 0, n);
	int cnt = 0;
	fori (i, 1, n + 1)
		cnt += ans[i];
	cout << cnt << endl;
	fori (i, 1, n + 1)
		if (ans[i])
			cout << i << ' ';
	cout << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e4 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

int n, q;
bitset<maxn> dp[4 * maxn];
vi seg[4 * maxn], ans;

void update(int u, int l, int r, int b, int e, int val)
{
	if (b <= l && r <= e)
	{
		seg[u].pb(val);
		return;
	}
	int mid = (l + r) / 2;
	if (b < mid)
		update(lchild(u), l, mid, b, e, val);
	if (e > mid)
		update(rchild(u), mid, r, b, e, val);
}

void dfs(int u, int l, int r)
{
	for (int i : seg[u])
		dp[u] |= (dp[u] << i);
	if (r - l == 1)
	{
		fori (i, 0, n + 1)
			if (dp[u][i])
				ans.pb(i);
		return;
	}
	int mid = (l + r) / 2;
	fori (i, 1, n + 1)
		if (dp[u][i])
		{
			dp[lchild(u)] |= dp[u];
			dp[rchild(u)] |= dp[u];
		}
	dfs(lchild(u), l, mid);
	dfs(rchild(u), mid, r);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fori (i, 0, maxn)
		dp[i][0] = true;

	cin >> n >> q;
	int l, r, x;
	fori (i, 0, q)
	{
		cin >> l >> r >> x;
		update(0, 0, n, l - 1, r, x);
	}
	dfs(0, 0, n);
	sort(all(ans));
	ans.resize(unique(all(ans)) - ans.begin());
	cout << ans.size() - 1 << endl;
	for (int i : ans)
		if (i)
			cout << i << ' ';
	cout << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e4 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

int n, q;
bitset<maxn> dp[4 * maxn], ans;
vi seg[4 * maxn];

void update(int u, int l, int r, int b, int e, int val)
{
	if (b <= l && r <= e)
	{
		seg[u].pb(val);
		return;
	}
	int mid = (l + r) / 2;
	if (b < mid)
		update(lchild(u), l, mid, b, e, val);
	if (e > mid)
		update(rchild(u), mid, r, b, e, val);
}

void dfs(int u, int l, int r)
{
	for (int i : seg[u])
		dp[u] |= (dp[u] << i);
	if (r - l == 1)
	{
		ans |= dp[u];
		return;
	}
	int mid = (l + r) / 2;
	dp[lchild(u)] |= dp[u];
	dp[rchild(u)] |= dp[u];
	dfs(lchild(u), l, mid);
	dfs(rchild(u), mid, r);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fori (i, 0, maxn)
		dp[i][0] = true;

	cin >> n >> q;
	int l, r, x;
	fori (i, 0, q)
	{
		cin >> l >> r >> x;
		update(0, 0, n, l - 1, r, x);
	}
	dfs(0, 0, n);
	int cnt = 0;
	fori (i, 1, n + 1)
		cnt += ans[i];
	cout << cnt << endl;
	fori (i, 1, n + 1)
		if (ans[i])
			cout << i << ' ';
	cout << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e4 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

int n, q;
bitset<maxn> dp[4 * maxn], ans;
vi seg[4 * maxn];

void update(int u, int l, int r, int b, int e, int val)
{
	if (b <= l && r <= e)
	{
		seg[u].pb(val);
		return;
	}
	int mid = (l + r) / 2;
	if (b < mid)
		update(lchild(u), l, mid, b, e, val);
	if (e > mid)
		update(rchild(u), mid, r, b, e, val);
}

void dfs(int u, int l, int r)
{
	for (int i : seg[u])
		dp[u] |= (dp[u] << i);
	if (r - l == 1)
	{
		ans |= dp[u];
		return;
	}
	int mid = (l + r) / 2;
	fori (i, 1, n + 1)
		if (dp[u][i])
		{
			dp[lchild(u)] |= dp[u];
			dp[rchild(u)] |= dp[u];
		}
	dfs(lchild(u), l, mid);
	dfs(rchild(u), mid, r);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fori (i, 0, maxn)
		dp[i][0] = true;

	cin >> n >> q;
	int l, r, x;
	fori (i, 0, q)
	{
		cin >> l >> r >> x;
		update(0, 0, n, l - 1, r, x);
	}
	dfs(0, 0, n);
	cout << ans.count() - 1 << endl;
	fori (i, 1, n + 1)
		if (ans[i])
			cout << i << ' ';
	cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10005;
const ll inf=0x3f3f3f3f3f3f3f3fll;
const ll mod=1000000000000007ll;
int n,m;
ll dp[N];
inline void add(int x){
	for(int i=N-1;i>=x;i--) dp[i]=(dp[i]+dp[i-x])%mod;
}
inline void del(int x){
	for(int i=x;i<N;i++) dp[i]=(dp[i]-dp[i-x]+mod)%mod;
}
vector<int> v[N];
int cnt[N];
int main(){
	int i,j;
	cin>>n>>m;
	dp[0]=1;
	for(i=1;i<=m;i++){
		int x,y,z;cin>>x>>y>>z;
		v[x].push_back(z);
		v[y+1].push_back(-z);
	}
	for(i=1;i<=n;i++){
		for(j=0;j<v[i].size();j++){
			int k=v[i][j];
			if(k>0) add(k);
			else del(-k);
		}
		for(j=1;j<N;j++) if(dp[j]) cnt[j]++;
	}
	int ans=0;
	for(i=1;i<=n;i++) ans+=bool(cnt[i]);
	cout<<ans<<endl;
	for(i=1;i<=n;i++) if(cnt[i]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10005;
const ll inf=0x3f3f3f3f3f3f3f3fll;
const ll mod=1004535809ll;
int n,m;
int dp[N];
inline void add(int x){
	for(int i=N-1;i;i--) dp[i]=(dp[i]+dp[i-x])%mod;
}
inline void del(int x){
	for(int i=1;i<N;i++) dp[i]=(dp[i]-dp[i-x]+mod)%mod;
}
vector<int> v[N];
int cnt[N];
int main(){
	int i,j;
	cin>>n>>m;
	dp[0]=1;
	for(i=1;i<=m;i++){
		int x,y,z;cin>>x>>y>>z;
		v[x].push_back(z);
		v[y+1].push_back(-z);
	}
	for(i=1;i<=n;i++){
		for(j=0;j<v[i].size();j++){
			int k=v[i][j];
			if(k>0) add(k);
			else del(-k);
		}
		for(j=1;j<N;j++) if(dp[j]) cnt[j]++;
	}
	int ans=0;
	for(i=1;i<=n;i++) ans+=bool(cnt[i]);
	cout<<ans<<endl;
	for(i=1;i<=n;i++) if(cnt[i]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10005;
const ll inf=0x3f3f3f3f3f3f3f3fll;
const ll mod=1000000000000007ll;
int n,m;
int dp[N];
inline void add(int x){
	for(int i=N-1;i>=x;i--) dp[i]=(dp[i]+dp[i-x])%mod;
}
inline void del(int x){
	for(int i=x;i<N;i++) dp[i]=(dp[i]-dp[i-x]+mod)%mod;
}
vector<int> v[N];
int cnt[N];
int main(){
	int i,j;
	cin>>n>>m;
	dp[0]=1;
	for(i=1;i<=m;i++){
		int x,y,z;cin>>x>>y>>z;
		v[x].push_back(z);
		v[y+1].push_back(-z);
	}
	for(i=1;i<=n;i++){
		for(j=0;j<v[i].size();j++){
			int k=v[i][j];
			if(k>0) add(k);
			else del(-k);
		}
		for(j=1;j<N;j++) if(dp[j]) cnt[j]++;
	}
	int ans=0;
	for(i=1;i<=n;i++) ans+=bool(cnt[i]);
	cout<<ans<<endl;
	for(i=1;i<=n;i++) if(cnt[i]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10005;
const ll inf=0x3f3f3f3f3f3f3f3fll;
const ll mod=1004535809ll;
int n,m;
int dp[N];
inline void add(int x){
	for(int i=N-1;i>=x;i--) dp[i]=(dp[i]+dp[i-x])%mod;
}
inline void del(int x){
	for(int i=x;i<N;i++) dp[i]=(dp[i]-dp[i-x]+mod)%mod;
}
vector<int> v[N];
int cnt[N];
int main(){
	int i,j;
	cin>>n>>m;
	dp[0]=1;
	for(i=1;i<=m;i++){
		int x,y,z;cin>>x>>y>>z;
		v[x].push_back(z);
		v[y+1].push_back(-z);
	}
	for(i=1;i<=n;i++){
		for(j=0;j<v[i].size();j++){
			int k=v[i][j];
			if(k>0) add(k);
			else del(-k);
		}
		for(j=1;j<N;j++) if(dp[j]) cnt[j]++;
	}
	int ans=0;
	for(i=1;i<=n;i++) ans+=bool(cnt[i]);
	cout<<ans<<endl;
	for(i=1;i<=n;i++) if(cnt[i]) cout<<i<<" ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1333333333333333;

bool comp(pair <int,int>& a, pair <int,int>& b) {
	if (a.first == b.first) return a.second > b.second;
	return a.first < b.first;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	vector <pair <int,int> >v;
	for (int i = 0; i < q; ++i) {
		int l, r, x;
		cin >> l >> r >> x;
		v.push_back(pair <int,int>(l, x));
		v.push_back(pair <int,int>(r, -x));
	}
	vector <bool>ans(n+1, false);
	vector <long long>dp(n+1, 0);
	dp[0] = 1;
	sort(v.begin(), v.end(), comp);
	for (int i = 0; i < n; ++i) {
		int x = v[i].second;
		if (x > 0) {
			for (int j = n-x; j >= 0; --j) {
				dp[j+x] = (dp[j+x] + dp[j])%MOD;
				if (dp[j+x]) ans[j+x] = true;
			}
		}
		else {
			for (int j = -x; j <= n; ++j) {
				dp[j] = (dp[j] - dp[j+x] + MOD)%MOD;
			}
		}
	}
	int c = 0;
	for (int i = 1; i <= n; ++i) {
		c += ans[i];
	}
	cout << c << endl;
	for (int i = 1; i <= n; ++i) {
		if (ans[i]) cout << i << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1333333333333333;

bool comp(pair <int,int>& a, pair <int,int>& b) {
	if (a.first == b.first) return a.second > b.second;
	return a.first < b.first;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	vector <pair <int,int> >v;
	for (int i = 0; i < q; ++i) {
		int l, r, x;
		cin >> l >> r >> x;
		v.push_back(pair <int,int>(l, x));
		v.push_back(pair <int,int>(r, -x));
	}
	vector <bool>ans(n+1, false);
	vector <long long>dp(n+1, 0);
	dp[0] = 1;
	sort(v.begin(), v.end(), comp);
	for (int i = 0; i < 2*q; ++i) {
		int x = v[i].second;
		if (x > 0) {
			for (int j = n-x; j >= 0; --j) {
				dp[j+x] = (dp[j+x] + dp[j])%MOD;
				if (dp[j+x]) ans[j+x] = true;
			}
		}
		else {
			x = -x;
			for (int j = x; j <= n; ++j) {
				dp[j] = (dp[j] - dp[j-x] + MOD)%MOD;
			}
		}
	}
	int c = 0;
	for (int i = 1; i <= n; ++i) {
		c += ans[i];
	}
	cout << c << endl;
	for (int i = 1; i <= n; ++i) {
		if (ans[i]) cout << i << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

const long long MOD = (1LL<<61)-1;

bool comp(pair <int,int>& a, pair <int,int>& b) {
	if (a.first == b.first) return a.second > b.second;
	return a.first < b.first;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	vector <pair <int,int> >v;
	for (int i = 0; i < q; ++i) {
		int l, r, x;
		cin >> l >> r >> x;
		v.push_back(pair <int,int>(l, x));
		v.push_back(pair <int,int>(r, -x));
	}
	vector <bool>ans(n+1, false);
	vector <long long>dp(n+1, 0);
	dp[0] = 1;
	sort(v.begin(), v.end(), comp);
	for (int i = 0; i < 2*q; ++i) {
		int x = v[i].second;
		if (x > 0) {
			for (int j = n-x; j >= 0; --j) {
				dp[j+x] = (dp[j+x] + dp[j])%MOD;
				if (dp[j+x]) ans[j+x] = true;
			}
		}
		else {
			x = -x;
			for (int j = x; j <= n; ++j) {
				dp[j] = (dp[j] - dp[j-x] + MOD)%MOD;
			}
		}
	}
	int c = 0;
	for (int i = 1; i <= n; ++i) {
		c += ans[i];
	}
	cout << c << endl;
	for (int i = 1; i <= n; ++i) {
		if (ans[i]) cout << i << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1333333333333333;

bool comp(pair <int,int>& a, pair <int,int>& b) {
	if (a.first == b.first) return a.second > b.second;
	return a.first < b.first;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	vector <pair <int,int> >v;
	for (int i = 0; i < q; ++i) {
		int l, r, x;
		cin >> l >> r >> x;
		v.push_back(pair <int,int>(l, x));
		v.push_back(pair <int,int>(r, -x));
	}
	vector <bool>ans(n+1, false);
	vector <long long>dp(n+1, 0);
	dp[0] = 1;
	sort(v.begin(), v.end(), comp);
	for (int i = 0; i < 2*q; ++i) {
		int x = v[i].second;
		if (x > 0) {
			for (int j = n-x; j >= 0; --j) {
				dp[j+x] = (dp[j+x] + dp[j])%MOD;
				if (dp[j+x]) ans[j+x] = true;
			}
		}
		else {
			for (int j = -x; j <= n; ++j) {
				dp[j] = dp[j] - dp[j+x];
				if (dp[j] < 0) dp[j] += MOD;
			}
		}
	}
	int c = 0;
	for (int i = 1; i <= n; ++i) {
		c += ans[i];
	}
	cout << c << endl;
	for (int i = 1; i <= n; ++i) {
		if (ans[i]) cout << i << " ";
	}
	cout << endl;
}


#include<bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define PI acos(-1.0)
using namespace std;

typedef long long ll;
const int mod=998244353;
ll dp[10010];
bool f[10010];
vector<int> st[10010],ed[10010];

ll add(ll &a,ll b)
{
    a+=b;
    if(a>=mod) a-=mod;
}

ll sub(ll &a,ll b)
{
    a-=b;
    if(a<0) a+=mod;
}

int main()
{
#ifdef LOCAL
    freopen("test.in","r",stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(0);
    int n,q;cin>>n>>q;
    for(int i=1;i<=q;i++){
        int l,r,x;cin>>l>>r>>x;
        st[l].push_back(x),ed[r+1].push_back(x);
    }
    dp[0]=1;
    for(int i=1;i<=n;i++){
        for(auto e:ed[i]){
            for(int j=e;j<=n;j++) sub(dp[j],dp[j-e]);
        }
        for(auto e:st[i]){
            for(int j=n;j>=e;j--) add(dp[j],dp[j-e]);
        }
        for(int j=1;j<=n;j++)
            if(dp[j]) f[j]=1;
    }
    vector<int> ans;
    for(int i=1;i<=n;i++)
        if(f[i]) ans.push_back(i);
    cout<<ans.size()<<endl;
    for(auto e:ans) cout<<e<<" ";
    return 0;
}


#include<bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define PI acos(-1.0)
using namespace std;

typedef long long ll;
ll dp[10010];
bool f[10010];
vector<int> st[10010],ed[10010];

int main()
{
#ifdef LOCAL
    freopen("test.in","r",stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(0);
    int n,q;cin>>n>>q;
    for(int i=1;i<=q;i++){
        int l,r,x;cin>>l>>r>>x;
        st[l].push_back(x),ed[r+1].push_back(x);
    }
    dp[0]=1;
    for(int i=1;i<=n;i++){
        for(auto e:ed[i]){
            for(int j=e;j<=n;j++) dp[j]-=dp[j-e];
        }
        for(auto e:st[i]){
            for(int j=n;j>=e;j--) dp[j]+=dp[j-e];
        }
        for(int j=1;j<=n;j++)
            if(dp[j]) f[j]=1;
    }
    vector<int> ans;
    for(int i=1;i<=n;i++)
        if(f[i]) ans.push_back(i);
    cout<<ans.size()<<endl;
    for(auto e:ans) cout<<e<<" ";
    return 0;
}


#include<bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define PI acos(-1.0)
using namespace std;

typedef long long ll;
const int mod=998244353;
ll dp[10010];
bool f[10010];
vector<int> st[10010],ed[10010];

int main()
{
#ifdef LOCAL
    freopen("test.in","r",stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(0);
    int n,q;cin>>n>>q;
    for(int i=1;i<=q;i++){
        int l,r,x;cin>>l>>r>>x;
        st[l].push_back(x),ed[r+1].push_back(x);
    }
    dp[0]=1;
    for(int i=1;i<=n;i++){
        for(auto e:ed[i]){
            for(int j=e;j<=n;j++){
                dp[j]-=dp[j-e];
                if(dp[j]<0) dp[j]+=mod;
            }
        }
        for(auto e:st[i]){
            for(int j=n;j>=e;j--){
                dp[j]+=dp[j-e];
                if(dp[j]>=mod) dp[j]-=mod;
            }
        }
        for(int j=1;j<=n;j++)
            if(dp[j]) f[j]=1;
    }
    vector<int> ans;
    for(int i=1;i<=n;i++)
        if(f[i]) ans.push_back(i);
    cout<<ans.size()<<endl;
    for(auto e:ans) cout<<e<<" ";
    return 0;
}


#include<bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define PI acos(-1.0)
using namespace std;

typedef long long ll;
const int mod=998244353;
ll dp[10010];
bool f[10010];
vector<int> st[10010],ed[10010];

int main()
{
#ifdef LOCAL
    freopen("test.in","r",stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(0);
    int n,q;cin>>n>>q;
    for(int i=1;i<=q;i++){
        int l,r,x;cin>>l>>r>>x;
        st[l].push_back(x),ed[r+1].push_back(x);
    }
    dp[0]=1;
    for(int i=1;i<=n;i++){
        for(auto e:ed[i]){
            for(int j=e;j<=n;j++) dp[j]=(dp[j]-dp[j-e]+mod)%mod;
        }
        for(auto e:st[i]){
            for(int j=n;j>=e;j--) dp[j]=(dp[j]+dp[j-e])%mod;
        }
        for(int j=1;j<=n;j++)
            if(dp[j]) f[j]=1;
    }
    vector<int> ans;
    for(int i=1;i<=n;i++)
        if(f[i]) ans.push_back(i);
    cout<<ans.size()<<endl;
    for(auto e:ans) cout<<e<<" ";
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 10004
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int n,q,l,r,x,jaw;
vector<int>ve[mx];
bitset<10003>bit[103],res,sem,lol;
int main(){
	cin>>n>>q;
	for(int j=0;j<n;j+=200)bit[j/200][0]=1;
	for(int i=1;i<=q;i++){
		cin>>l>>r>>x;
		l--,r--;
		for(int j=0;j<n;j+=200){
			int ke=j/200;
			int kiri=j,kanan=j+200-1;
			kanan=min(kanan,n-1);
			if(kiri>r || kanan<l)continue;
			//cout<<kiri<<' '<<kanan<<" -> "<<ke<<endl;
			if(l<=kiri && kanan<=r){
				sem=bit[ke];
				sem=sem<<x;
				bit[ke]|=sem;
			}
			for(int k=kiri;k<=kanan;k++){
				if(k>r || k<l)continue;
			//	cout<<k<<" -> "<<x<<endl;
				ve[k].pb(x);
			}
		}
	}
	for(int i=0;i<n;i++){
		int ke=i/200;
		lol=bit[ke];
		for(int j:ve[i]){
			sem=lol;
			sem=sem<<j;
			lol|=sem;
		}
		res|=lol;
	}
	for(int i=1;i<=n;i++){
		if(res[i])jaw++;
	}
	cout<<jaw<<endl;
	for(int i=1;i<=n;i++){
		if(res[i])cout<<i<<' ';
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 10004
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int n,q,l,r,x,jaw;
vector<int>ve[mx];
bitset<10003>bit[103],res,sem,lol;
int main(){
	cin>>n>>q;
	for(int j=0;j<n;j+=100)bit[j/100][0]=1;
	for(int i=1;i<=q;i++){
		cin>>l>>r>>x;
		l--,r--;
		for(int j=0;j<n;j+=100){
			int ke=j/100;
			int kiri=j,kanan=j+100-1;
			kanan=min(kanan,n-1);
			if(kiri>r || kanan<l)continue;
			//cout<<kiri<<' '<<kanan<<" -> "<<ke<<endl;
			if(l<=kiri && kanan<=r){
				sem=bit[ke];
				sem=sem<<x;
				bit[ke]|=sem;
			}
			for(int k=kiri;k<=kanan;k++){
				if(k>r || k<l)continue;
			//	cout<<k<<" -> "<<x<<endl;
				ve[k].pb(x);
			}
		}
	}
	for(int i=0;i<n;i++){
		int ke=i/100;
		lol=bit[ke];
		for(int j:ve[i]){
			sem=lol;
			sem=sem<<j;
			lol|=sem;
		}
		res|=lol;
	}
	for(int i=1;i<=n;i++){
		if(res[i])jaw++;
	}
	cout<<jaw<<endl;
	for(int i=1;i<=n;i++){
		if(res[i])cout<<i<<' ';
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 10004
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int n,q,l,r,x,jaw;
vector<int>ve[mx];
bitset<10003>bit[1003],res,sem,lol;
int main(){
	cin>>n>>q;
	for(int j=0;j<n;j+=20)bit[j/20][0]=1;
	for(int i=1;i<=q;i++){
		cin>>l>>r>>x;
		l--,r--;
		for(int j=0;j<n;j+=20){
			int ke=j/40;
			int kiri=j,kanan=j+20-1;
			kanan=min(kanan,n-1);
			if(kiri>r || kanan<l)continue;
			//cout<<kiri<<' '<<kanan<<" -> "<<ke<<endl;
			if(l<=kiri && kanan<=r){
				sem=bit[ke];
				sem=sem<<x;
				bit[ke]|=sem;
			}
			for(int k=kiri;k<=kanan;k++){
				if(k>r || k<l)continue;
			//	cout<<k<<" -> "<<x<<endl;
				ve[k].pb(x);
			}
		}
	}
	for(int i=0;i<n;i++){
		int ke=i/20;
		lol=bit[ke];
		for(int j:ve[i]){
			sem=lol;
			sem=sem<<j;
			lol|=sem;
		}
		res|=lol;
	}
	for(int i=1;i<=n;i++){
		if(res[i])jaw++;
	}
	cout<<jaw<<endl;
	for(int i=1;i<=n;i++){
		if(res[i])cout<<i<<' ';
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 10004
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int n,q,l,r,x,jaw;
vector<int>ve[mx];
bitset<10003>bit[103],ini[mx],res,sem;
int main(){
	cin>>n>>q;
	for(int j=0;j<n;j+=100)bit[j/100][0]=1;
	for(int i=1;i<=q;i++){
		cin>>l>>r>>x;
		l--,r--;
		for(int j=0;j<n;j+=100){
			int ke=j/100;
			int kiri=j,kanan=j+100-1;
			kanan=min(kanan,n-1);
			if(kiri>r || kanan<l)continue;
			//cout<<kiri<<' '<<kanan<<" -> "<<ke<<endl;
			if(l<=kiri && kanan<=r){
				sem=bit[ke];
				sem=sem<<x;
				bit[ke]|=sem;
			}
			for(int k=kiri;k<=kanan;k++){
				if(k>r || k<l)continue;
			//	cout<<k<<" -> "<<x<<endl;
				ve[k].pb(x);
			}
		}
	}
	for(int i=0;i<n;i++){
		int ke=i/100;
		ini[i]=bit[ke];
		for(int j:ve[i]){
			sem=ini[i];
			sem=sem<<j;
			ini[i]|=sem;
		}
	}
	for(int i=0;i<n;i++){
		res=res|ini[i];
	}
	for(int i=1;i<=n;i++){
		if(res[i])jaw++;
	}
	cout<<jaw<<endl;
	for(int i=1;i<=n;i++){
		if(res[i])cout<<i<<' ';
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 1004
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int n,q,l,r,x,jaw;
vector<int>ve[mx];
bitset<1003>bit[103],ini[mx],res,sem;
int main(){
	cin>>n>>q;
	for(int j=0;j<n;j+=100)bit[j/100][0]=1;
	for(int i=1;i<=q;i++){
		cin>>l>>r>>x;
		l--,r--;
		for(int j=0;j<n;j+=100){
			int ke=j/100;
			int kiri=j,kanan=j+100-1;
			kanan=min(kanan,n-1);
			if(kiri>r || kanan<l)continue;
			//cout<<kiri<<' '<<kanan<<" -> "<<ke<<endl;
			if(l<=kiri && kanan<=r){
				sem=bit[ke];
				sem=sem<<x;
				bit[ke]|=sem;
			}
			for(int k=kiri;k<=kanan;k++){
				if(k>r || k<l)continue;
			//	cout<<k<<" -> "<<x<<endl;
				ve[k].pb(x);
			}
		}
	}
	for(int i=0;i<n;i++){
		int ke=i/100;
		ini[i]=bit[ke];
		for(int j:ve[i]){
			sem=ini[i];
			sem=sem<<j;
			ini[i]|=sem;
		}
	}
	for(int i=0;i<n;i++){
		res=res|ini[i];
	}
	for(int i=1;i<=n;i++){
		if(res[i])jaw++;
	}
	cout<<jaw<<endl;
	for(int i=1;i<=n;i++){
		if(res[i])cout<<i<<' ';
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 10004
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int n,q,l,r,x,jaw;
vector<int>ve[mx];
bitset<10003>bit[1003],res,sem,lol;
int main(){
	cin>>n>>q;
	for(int j=0;j<n;j+=50)bit[j/50][0]=1;
	for(int i=1;i<=q;i++){
		cin>>l>>r>>x;
		l--,r--;
		for(int j=0;j<n;j+=50){
			int ke=j/50;
			int kiri=j,kanan=j+50-1;
			kanan=min(kanan,n-1);
			if(kiri>r || kanan<l)continue;
			//cout<<kiri<<' '<<kanan<<" -> "<<ke<<endl;
			if(l<=kiri && kanan<=r){
				sem=bit[ke];
				sem=sem<<x;
				bit[ke]|=sem;
			}
			for(int k=kiri;k<=kanan;k++){
				if(k>r || k<l)continue;
			//	cout<<k<<" -> "<<x<<endl;
				ve[k].pb(x);
			}
		}
	}
	for(int i=0;i<n;i++){
		int ke=i/50;
		lol=bit[ke];
		for(int j:ve[i]){
			sem=lol;
			sem=sem<<j;
			lol|=sem;
		}
		res|=lol;
	}
	for(int i=1;i<=n;i++){
		if(res[i])jaw++;
	}
	cout<<jaw<<endl;
	for(int i=1;i<=n;i++){
		if(res[i])cout<<i<<' ';
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 10004
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int n,q,l,r,x,jaw;
vector<int>ve[mx];
bitset<10003>bit[1003],res,sem,lol;
int main(){
	cin>>n>>q;
	for(int j=0;j<n;j+=40)bit[j/40][0]=1;
	for(int i=1;i<=q;i++){
		cin>>l>>r>>x;
		l--,r--;
		for(int j=0;j<n;j+=40){
			int ke=j/40;
			int kiri=j,kanan=j+40-1;
			kanan=min(kanan,n-1);
			if(kiri>r || kanan<l)continue;
			//cout<<kiri<<' '<<kanan<<" -> "<<ke<<endl;
			if(l<=kiri && kanan<=r){
				sem=bit[ke];
				sem=sem<<x;
				bit[ke]|=sem;
			}
			for(int k=kiri;k<=kanan;k++){
				if(k>r || k<l)continue;
			//	cout<<k<<" -> "<<x<<endl;
				ve[k].pb(x);
			}
		}
	}
	for(int i=0;i<n;i++){
		int ke=i/40;
		lol=bit[ke];
		for(int j:ve[i]){
			sem=lol;
			sem=sem<<j;
			lol|=sem;
		}
		res|=lol;
	}
	for(int i=1;i<=n;i++){
		if(res[i])jaw++;
	}
	cout<<jaw<<endl;
	for(int i=1;i<=n;i++){
		if(res[i])cout<<i<<' ';
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 10004
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int n,q,l,r,x,jaw;
vector<int>ve[mx];
bitset<10003>bit[103],res,sem,lol;
int main(){
	cin>>n>>q;
	for(int j=0;j<n;j+=200)bit[j/200][0]=1;
	for(int i=1;i<=q;i++){
		cin>>l>>r>>x;
		l--,r--;
		for(int j=0;j<n;j+=200){
			int ke=j/200;
			int kiri=j,kanan=j+200-1;
			kanan=min(kanan,n-1);
			if(kiri>r || kanan<l)continue;
			//cout<<kiri<<' '<<kanan<<" -> "<<ke<<endl;
			if(l<=kiri && kanan<=r){
				sem=bit[ke];
				sem=sem<<x;
				bit[ke]|=sem;
				continue;
			}
			for(int k=kiri;k<=kanan;k++){
				if(k>r || k<l)continue;
			//	cout<<k<<" -> "<<x<<endl;
				ve[k].pb(x);
			}
		}
	}
	for(int i=0;i<n;i++){
		int ke=i/200;
		lol=bit[ke];
		for(int j:ve[i]){
			sem=lol;
			sem=sem<<j;
			lol|=sem;
		}
		res|=lol;
	}
	for(int i=1;i<=n;i++){
		if(res[i])jaw++;
	}
	cout<<jaw<<endl;
	for(int i=1;i<=n;i++){
		if(res[i])cout<<i<<' ';
	}
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 1,M = 1e9 + 9;
int dp[N] = {1},n,Q,last;
bool ans[N];
struct lol{
	int id,val;
	bool what;
	lol(int a = 0,int b = 0,bool c = 0){id = a;val = b;what = c;}
	bool operator<(const lol&a)const{return id < a.id;}
}q[2*N];
void add(int val){
	for(int i = n;i - val >= 0;i--){
		dp[i]+=dp[i - val];
		if(dp[i])ans[i] = 1;
	}
}
void rem(int val){
	for(int i = val;i <= n;i++)dp[i]-=dp[i - val];
}
int main(){
// 	freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&Q);
	for(int i = 0,l,r,x;i < Q;i++){
		scanf("%d%d%d",&l,&r,&x);
		q[i] = lol(l,x,0);
		q[Q + i] = lol(r,x,1);
	}
	sort(q,q + 2*Q);
	for(int i = 0;i < 2*Q;i++)
		if(!q[i].what)add(q[i].val);
		else rem(q[i].val);
	Q = 0;
	for(int i = 1;i <= n;i++)Q+=ans[i];
	printf("%d\n",Q);
	for(int i = 1;i <= n;i++)if(ans[i])printf("%d ",i);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 1;
int dp[N] = {1},n,Q,last;
bool ans[N];
struct lol{
	int id,val;
	bool what;
	lol(int a = 0,int b = 0,bool c = 0){id = a;val = b;what = c;}
	bool operator<(const lol&a)const{
		if(id != a.id)return id < a.id;
		return what < a.what;
	}
}q[2*N];
void add(int val){
	for(int i = n;i >= val;i--){
		dp[i]+=dp[i - val];
		if(dp[i])ans[i] = 1;
	}
}
void rem(int val){
	for(int i = val;i <= n;i++)dp[i]-=dp[i - val];
}
int main(){
// 	freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&Q);
	for(int i = 0,l,r,x;i < Q;i++){
		scanf("%d%d%d",&l,&r,&x);
		q[last++] = lol(l,x,0);
		q[last++] = lol(r,x,1);
	}
	sort(q,q + last);
	for(int i = 0;i < last;i++)
		if(!q[i].what)add(q[i].val);
		else rem(q[i].val);
	Q = 0;
	for(int i = 1;i <= n;i++)Q+=ans[i];
	printf("%d\n",Q);
	for(int i = 1;i <= n;i++)if(ans[i])printf("%d ",i);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 1;
int dp[N] = {1},n,Q;
bool ans[N];
struct lol{
	int id,val;
	bool what;
	lol(int a = 0,int b = 0,bool c = 0){id = a;val = b;what = c;}
	bool operator<(const lol&a)const{
		if(id != a.id)return id < a.id;
		return what < a.what;
	}
}q[2*N];
void add(int val){
	for(int i = n;i >= val;i--){
		dp[i]+=dp[i - val];
		if(dp[i])ans[i] = 1;
	}
}
void rem(int val){
	for(int i = val;i <= n;i++)dp[i]-=dp[i - val];
}
int main(){
// 	freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&Q);
	for(int i = 0,l,r,x;i < Q;i++){
		scanf("%d%d%d",&l,&r,&x);
		q[i] = lol(l,x,0);
		q[Q + i] = lol(r,x,1);
	}
	sort(q,q + 2*Q);
	for(int i = 0;i < 2*Q;i++)
		if(!q[i].what)add(q[i].val);
		else rem(q[i].val);
	Q = 0;
	for(int i = 1;i <= n;i++)Q+=ans[i];
	printf("%d\n",Q);
	for(int i = 1;i <= n;i++)if(ans[i])printf("%d ",i);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 1,M = 1e9 + 7;
int dp[N] = {1},n,Q;
bool ans[N];
struct lol{
	int id,val;
	bool what;
	lol(int a = 0,int b = 0,bool c = 0){id = a;val = b;what = c;}
	bool operator<(const lol&a)const{return id < a.id;}
}q[2*N];
void add(int &a,int b){
	a+=b;
	if(a >= M)a-=M;
	if(a < 0)a+=M;
}
void add(int val){
	for(int i = n;i - val >= 0;i--){
		add(dp[i],dp[i - val]);
		if(dp[i])ans[i] = 1;
	}
}
void rem(int val){
	for(int i = val;i <= n;i++)add(dp[i],dp[i - val]);
}
int main(){
// 	freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&Q);
	for(int i = 0,l,r,x;i < Q;i++){
		scanf("%d%d%d",&l,&r,&x);
		q[i] = lol(l,x,0);
		q[n + i] = lol(r,x,1);
	}
	sort(q,q + 2*Q);
	for(int i = 0;i < 2*Q;i++)
		if(!q[i].what)add(q[i].val);
		else rem(q[i].val);
	Q= 0;
	for(int i = 1;i <= n;i++)Q+=ans[i];
	printf("%d\n",Q);
	for(int i = 1;i <= n;i++)if(ans[i])printf("%d ",i);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 1;
int dp[N] = {1},n,Q,last;
bool ans[N];
struct lol{
	int id,val;
	bool what;
	lol(int a = 0,int b = 0,bool c = 0){id = a;val = b;what = c;}
	bool operator<(const lol&a)const{
		if(id != a.id)return id < a.id;
		return what < what;
	}
}q[2*N];
void add(int val){
	for(int i = n;i >= val;i--){
		dp[i]+=dp[i - val];
		if(dp[i])ans[i] = 1;
	}
}
void rem(int val){
	for(int i = val;i <= n;i++)dp[i]-=dp[i - val];
}
int main(){
// 	freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&Q);
	for(int i = 0,l,r,x;i < Q;i++){
		scanf("%d%d%d",&l,&r,&x);
		q[last++] = lol(l,x,0);
		q[last++] = lol(r,x,1);
	}
	sort(q,q + last);
	for(int i = 0;i < last;i++)
		if(!q[i].what)add(q[i].val);
		else rem(q[i].val);
	Q = 0;
	for(int i = 1;i <= n;i++)Q+=ans[i];
	printf("%d\n",Q);
	for(int i = 1;i <= n;i++)if(ans[i])printf("%d ",i);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 1,M = 1e9 + 9;
int dp[N] = {1},n,Q,last;
bool ans[N];
struct lol{
	int id,val;
	bool what;
	lol(int a = 0,int b = 0,bool c = 0){id = a;val = b;what = c;}
	bool operator<(const lol&a)const{
		if(id != a.id)return id < a.id;
		return what < what;
	}
}q[2*N];
void add(int &a,int b){
	a+=b;
	if(a >= M)a-=M;
	if(a < 0)a+=M;
}
void add(int val){
	for(int i = n;i - val >= 0;i--){
		add(dp[i],dp[i - val]);
		if(dp[i])ans[i] = 1;
	}
}
void rem(int val){
	for(int i = val;i <= n;i++)add(dp[i],-dp[i - val]);
}
int main(){
// 	freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&Q);
	for(int i = 0,l,r,x;i < Q;i++){
		scanf("%d%d%d",&l,&r,&x);
		q[i] = lol(l,x,0);
		q[Q + i] = lol(r,x,1);
	}
	sort(q,q + 2*Q);
	for(int i = 0;i < 2*Q;i++)
		if(!q[i].what)add(q[i].val);
		else rem(q[i].val);
	Q = 0;
	for(int i = 1;i <= n;i++)Q+=ans[i];
	printf("%d\n",Q);
	for(int i = 1;i <= n;i++)if(ans[i])printf("%d ",i);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 1,M = 1e9 + 7;
int dp[N] = {1},n,Q,last;
bool ans[N];
struct lol{
	int id,val;
	bool what;
	lol(int a = 0,int b = 0,bool c = 0){id = a;val = b;what = c;}
	bool operator<(const lol&a)const{return id < a.id;}
}q[2*N];
void add(int &a,int b){
	a+=b;
	if(a >= M)a-=M;
	if(a < 0)a+=M;
}
void add(int val){
	for(int i = n;i - val >= 0;i--){
		add(dp[i],dp[i - val]);
		if(dp[i])ans[i] = 1;
	}
}
void rem(int val){
	for(int i = val;i <= n;i++)add(dp[i],-dp[i - val]);
}
int main(){
// 	freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&Q);
	for(int i = 0,l,r,x;i < Q;i++){
		scanf("%d%d%d",&l,&r,&x);
		q[i] = lol(l,x,0);
		q[Q + i] = lol(r,x,1);
	}
	sort(q,q + 2*Q);
	for(int i = 0;i < 2*Q;i++)
		if(!q[i].what)add(q[i].val);
		else rem(q[i].val);
	Q= 0;
	for(int i = 1;i <= n;i++)Q+=ans[i];
	printf("%d\n",Q);
	for(int i = 1;i <= n;i++)if(ans[i])printf("%d ",i);
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

struct node
{
    int l, r, x;
    bool operator < (node n)
    {
        return l < n.l;
    }
};

bool vis[10001];
const int size = 1e4;
bool dp[size+1];

main()
{
    memset(vis, 0, sizeof(vis));
//    fastread;
    int n, Q; scanf("%lld %lld", &n, &Q);
    node a[Q+1];
    f(i, 1, Q+1) scanf("%lld %lld %lld", &a[i].l, &a[i].r, &a[i].x);
//    f(i, 1, Q+1) a[i] = {i, i, i};
    sort(a+1, a+Q+1);

    int l = 0, s = 0;
    f(i, 1, n+1)
    {
        int r = n+1;
        f(j, 1, Q+1)
            if(a[j].l > l) r = min(r, a[j].r);
        vector<int> v;
        f(j, 1, Q+1)
            if(a[j].l <= l && a[j].r >= l) v.pb(a[j].x);
            else if(a[j].l > l) break;
        s += v.size();
        if(r > n) break;
        memset(dp, 0, sizeof(dp));  dp[0] = 1;
        for(int j : v)
            for(int k = n-j; k >= 0; k--)
                dp[k+j] |= dp[k];
    //    cout<<"a";
    //    f(i, 1, n+1)  cout<<dp[i]<<" "; cout<<"\n";
        f(j, 1, n+1) vis[j] = vis[j] | dp[j];
        l = r;
    }

    int c = 0;
    f(i, 1, n+1) c += vis[i];
    printf("%lld\n", c);
    f(i, 1, n+1)
        if(vis[i]) printf("%lld ", i);
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

struct node
{
    int l, r, x;
    bool operator < (node n)
    {
        return l < n.l;
    }
};

bool vis[10001];
const int size = 1e4;
bool dp[size+1];

main()
{
    memset(vis, 0, sizeof(vis));
//    fastread;
    int n, Q; scanf("%lld %lld", &n, &Q);
    node a[Q+1];
    f(i, 1, Q+1) scanf("%lld %lld %lld", &a[i].l, &a[i].r, &a[i].x);
    //f(i, 1, Q+1) a[i] = {i, i, i};
    sort(a+1, a+Q+1);

    int l = 0, s = 0;
    f(i, 1, n+1)
    {
        int r = n+1;
        f(j, 1, Q+1)
            if(a[j].l > l) r = min(r, a[j].r);
        vector<int> v;
        f(j, 1, Q+1)
            if(a[j].l <= r && a[j].r >= r) v.pb(a[j].x);
            else if(a[j].l > r) break;
        s += v.size();
        if(r > n) break;
        memset(dp, 0, sizeof(dp));  dp[0] = 1;
        for(int j : v)
            for(int k = n-j; k >= 0; k--)
                dp[k+j] |= dp[k];
    //    cout<<"a";
    //    f(i, 1, n+1)  cout<<dp[i]<<" "; cout<<"\n";
        f(j, 1, n+1) vis[j] = vis[j] | dp[j];
        l = r;
    }

    int c = 0;
    f(i, 1, n+1) c += vis[i];
    printf("%lld\n", c);
    f(i, 1, n+1)
        if(vis[i]) printf("%lld ", i);
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

struct node
{
    int l, r, x;
    bool operator < (node n)
    {
        return l < n.l;
    }
};

bool vis[10001];
const int size = 1e4;
bool dp[size+1];

main()
{
    memset(vis, 0, sizeof(vis));
//    fastread;
    int n, Q; scanf("%lld %lld", &n, &Q);
    node a[Q+1];
    f(i, 1, Q+1) scanf("%lld %lld %lld", &a[i].l, &a[i].r, &a[i].x);
//    f(i, 1, Q+1) a[i] = {i, i, i};
    sort(a+1, a+Q+1);

    int l = 0, s = 0;
    f(i, 1, n+1)
    {
        int r = n+1;
        bool x = 0;
        f(j, 1, Q+1)
        {
            if(a[j].l > l) x = 1;
            if(a[j].r > l) r = min(r, a[j].r);
        }
        vector<int> v;
        f(j, 1, Q+1)
            if(a[j].l <= r && a[j].r >= r) v.pb(a[j].x);
            else if(a[j].l > r) break;
        s += v.size();
        if(!x) break;
        memset(dp, 0, sizeof(dp));  dp[0] = 1;
        for(int j : v)
            for(int k = n-j; k >= 0; k--)
                dp[k+j] |= dp[k];
    //    cout<<"a";
    //    f(i, 1, n+1)  cout<<dp[i]<<" "; cout<<"\n";
        f(j, 1, n+1) vis[j] = vis[j] | dp[j];
        l = r;
    }

    int c = 0;
    f(i, 1, n+1) c += vis[i];
    printf("%lld\n", c);
    f(i, 1, n+1)
        if(vis[i]) printf("%lld ", i);
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

struct node
{
    int l, r, x;
    bool operator < (node n)
    {
        return l < n.l;
    }
};

bool vis[10001];
const int size = 1e4;
bool dp[size+1];

main()
{
    memset(vis, 0, sizeof(vis));
//    fastread;
    int n, Q; scanf("%lld %lld", &n, &Q);
    node a[Q+1];
    f(i, 1, Q+1) scanf("%lld %lld %lld", &a[i].l, &a[i].r, &a[i].x);
//    f(i, 1, Q+1) a[i] = {i, i, i};
    sort(a+1, a+Q+1);

    int l = 0, s = 0;
    f(i, 1, n+1)
    {
        int r = n+1;
        bool x = 0;
        f(j, 1, Q+1)
        {
            if(a[j].l > l) x = 1;
            if(a[j].r > l) r = min(r, a[j].r);
        }
        vector<int> v;
        f(j, 1, Q+1)
            if(a[j].l <= r && a[j].r >= r) v.pb(a[j].x);
            else if(a[j].l > r) break;
        s += v.size();
        if(s > 3*Q) return -1;
        if(!x) break;
        memset(dp, 0, sizeof(dp));  dp[0] = 1;
        for(int j : v)
            for(int k = n-j; k >= 0; k--)
                dp[k+j] |= dp[k];
    //    cout<<"a";
    //    f(i, 1, n+1)  cout<<dp[i]<<" "; cout<<"\n";
        f(j, 1, n+1) vis[j] = vis[j] | dp[j];
        l = r;
    }

    int c = 0;
    f(i, 1, n+1) c += vis[i];
    printf("%lld\n", c);
    f(i, 1, n+1)
        if(vis[i]) printf("%lld ", i);
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

struct node
{
    int l, r, x;
};
bool cmp(node a, node b)
{
    return a.l < b.l;
}
bool vis[10001];
const int size = 1e4;
bool dp[size+1];

main()
{
    memset(vis, 0, sizeof(vis));
//    fastread;
    int n, Q; scanf("%lld %lld", &n, &Q);
    node a[Q+1];
    f(i, 1, Q+1) scanf("%lld %lld %lld", &a[i].l, &a[i].r, &a[i].x);
//    f(i, 1, Q+1) a[i] = {i, i, i};
//    f(i, 1, Q) a[i] = {1, i, i};  a[Q] = {n, n, n};
    sort(a+1, a+Q+1, cmp);

    int l = 0, s = 0;
    f(i, 1, n+1)
    {
        int r = n+1;
        node tt = {l, 0, 0};
        int x = upper_bound(a+1, a+n+1, tt, cmp) - a;
    //    cout<<x<<" ";
        if(x == n+1) break;
        f(j, 1, Q+1)
            if(a[j].r >= a[x].l) r = min(r, a[j].r);
        vector<int> v;
        f(j, 1, Q+1)
            if(a[j].l <= r && a[j].r >= r) v.pb(a[j].x);
            else if(a[j].l > r) break;
        s += v.size();
        if(s > 3*Q) return -1;
        //if(!x) break;
        memset(dp, 0, sizeof(dp));  dp[0] = 1;
        for(int j : v)
            for(int k = n-j; k >= 0; k--)
                dp[k+j] |= dp[k];
    //    cout<<"a";
    //    f(i, 1, n+1)  cout<<dp[i]<<" "; cout<<"\n";
        f(j, 1, n+1) vis[j] = vis[j] | dp[j];
        l = r;
    }

    int c = 0;
    f(i, 1, n+1) c += vis[i];
    printf("%lld\n", c);
    f(i, 1, n+1)
        if(vis[i]) printf("%lld ", i);
}


// SOLUTION SEEN

#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

bool vis[10001];

main()
{
    memset(vis, 0, sizeof(vis));
    fastread;
    int n, Q; cin>>n>>Q;
    vector<key> v[n+1];
    f(i, 1, n+1)
    {
        int l, r, x; cin>>l>>r>>x;
        v[l].pb({r, x});
    }
    int dp[n+1]; memset(dp, 0, sizeof(dp));  dp[0] = n;

    f(i, 1, n+1)
    {
        for(key k : v[i])
        {
            for(int j = n; j >= k.ss; j--)
            {
                dp[j] = max(dp[j], min(dp[j-k.ss], k.ff)); //cout<<"a";
                if(dp[j] >= i) vis[j] = 1;
            }
        }
    }
    //f(l, 1, n+1) cout<<dp[l]<<" "; cout<<"\n";
    int c = 0;
    f(i, 1, n+1) c += vis[i];
    cout<<c<<"\n";
    f(i, 1, n+1) if(vis[i]) cout<<i<<" ";
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

struct node
{
    int l, r, x;
    bool operator < (node n)
    {
        return l < n.l;
    }
};

bool vis[10001];
const int size = 1e4;
bool dp[size+1];

main()
{
    memset(vis, 0, sizeof(vis));
//    fastread;
    int n, Q; scanf("%lld %lld", &n, &Q);
    node a[Q+1];
    f(i, 1, Q+1) scanf("%lld %lld %lld", &a[i].l, &a[i].r, &a[i].x);
//    f(i, 1, Q+1) a[i] = {i, i, i};
    sort(a+1, a+Q+1);

    int l = 0, s = 0;
    f(i, 1, n+1)
    {
        int r = n+1;
        f(j, 1, Q+1)
            if(a[j].l > l) r = min(r, a[j].r);
        vector<int> v;
        f(j, 1, Q+1)
            if(a[j].l <= r && a[j].r >= r) v.pb(a[j].x);
            else if(a[j].l > r) break;
        s += v.size();
        if(r > n) break;
        memset(dp, 0, sizeof(dp));  dp[0] = 1;
        for(int j : v)
            for(int k = n-j; k >= 0; k--)
                dp[k+j] |= dp[k];
    //    cout<<"a";
    //    f(i, 1, n+1)  cout<<dp[i]<<" "; cout<<"\n";
        f(j, 1, n+1) vis[j] = vis[j] | dp[j];
        l = r;
    }

    int c = 0;
    f(i, 1, n+1) c += vis[i];
    printf("%lld\n", c);
    f(i, 1, n+1)
        if(vis[i]) printf("%lld ", i);
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

struct node
{
    int l, r, x;
    bool operator < (node n)
    {
        return l < n.l;
    }
};

bool vis[10001];
const int size = 1e4;
bool dp[size+1][size+1];

main()
{
    memset(dp, 0, sizeof(dp)); f(i, 0, size+1) dp[0][i] = 1;
    memset(vis, 0, sizeof(vis));
    fastread;
    int n, Q; scanf("%lld %lld", &n, &Q);
    node a[Q+1];
    f(i, 1, Q+1) scanf("%lld %lld %lld", &a[i].l, &a[i].r, &a[i].x);
    //f(i, 1, Q+1) a[i] = {i, i, i};
    sort(a+1, a+Q+1);

    int l = 0, s = 0;
    f(i, 1, n+1)
    {
        int r = n+1;
        f(j, 1, Q+1)
            if(a[j].l > l) r = min(r, a[j].r);
        vector<int> v;
        f(j, 1, Q+1)
            if(a[j].l <= r && a[j].r >= r) v.pb(a[j].x);
            else if(a[j].l > r) break;
        s += v.size();
        if(s > 3*Q) return -1;
        f(i, 1, n+1)
            f(j, 0, v.size())
            {
                dp[i][j+1] = dp[i][j];
                if(v[j] <= i)
                    dp[i][j+1] |= dp[i-v[j]][j];
            }
    //    f(i, 1, n+1){ f(j, 1, v.size() +1 ) cout<<dp[i][j]<<" "; cout<<"\n";} cout<<"\n";
        f(j, 1, n+1) vis[j] = vis[j] | dp[j][v.size()];
        l = r;
    }

    int c = 0;
    f(i, 1, n+1) c += vis[i];
    printf("%lld\n", c);
    f(i, 1, n+1)
        if(vis[i]) printf("%lld ", i);
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

struct node
{
    int l, r, x;
    bool operator < (node n)
    {
        return l < n.l;
    }
};

bool vis[10001];
const int size = 1e4;
bool dp[size+1][size+1];

main()
{
    memset(dp, 0, sizeof(dp)); f(i, 0, size+1) dp[0][i] = 1;
    memset(vis, 0, sizeof(vis));
    fastread;
    int n, Q; scanf("%lld %lld", &n, &Q);
    node a[Q+1];
    f(i, 1, Q+1) scanf("%lld %lld %lld", &a[i].l, &a[i].r, &a[i].x);
    sort(a+1, a+Q+1);

    int l = 0;
    f(i, 1, n+1)
    {
        int r = n+1;
        f(j, 1, Q+1)
            if(a[j].l > l) r = min(r, a[j].r);
        vector<int> v;
        f(j, 1, Q+1)
            if(a[j].l <= r && a[j].r >= r) v.pb(a[j].x);
            else if(a[j].l > r) break;

        f(i, 1, n+1)
            f(j, 0, v.size())
            {
                dp[i][j+1] = dp[i][j];
                if(v[j] <= i)
                    dp[i][j+1] |= dp[i-v[j]][j];
            }
    //    f(i, 1, n+1){ f(j, 1, v.size() +1 ) cout<<dp[i][j]<<" "; cout<<"\n";} cout<<"\n";
        f(j, 1, n+1) vis[j] = vis[j] | dp[j][v.size()];
        l = r;
    }

    int c = 0;
    f(i, 1, n+1) c += vis[i];
    printf("%lld\n", c);
    f(i, 1, n+1)
        if(vis[i]) printf("%lld ", i);
}


// SOLUTION SEEN

#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

bool vis[10001];

main()
{
    memset(vis, 0, sizeof(vis));
    fastread;
    int n, Q; cin>>n>>Q;
    vector<key> v[n+1];
    f(i, 1, Q+1)
    {
        int l, r, x; cin>>l>>r>>x;
        v[l].pb({r, x});
    }
    int dp[n+1]; memset(dp, 0, sizeof(dp));  dp[0] = n;

    f(i, 1, n+1)
    {
        for(key k : v[i])
        {
            for(int j = n; j >= k.ss; j--)
            {
                dp[j] = max(dp[j], min(dp[j-k.ss], k.ff)); //cout<<"a";
                if(dp[j] >= i) vis[j] = 1;
            }
    //        f(l, 1, n+1) cout<<dp[l]<<" "; cout<<"\n";
        }
    }
    int c = 0;
    f(i, 1, n+1) c += vis[i];
    cout<<c<<"\n";
    f(i, 1, n+1) if(vis[i]) cout<<i<<" ";
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef int ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

#define fread           freopen("input.txt","r",stdin)
#define fwrite          freopen("output.txt","w",stdout)
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define memo(ara,val)   memset(ara,val,sizeof(ara))
#define II              ( { int a ; read(a) ; a; } )
#define LL              ( { ll a ; read(a) ; a; } )
#define DD              ({double a; scanf("%lf", &a); a;})
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              printf("\n")
#define sc(x)           scanf("%lld",&x)
#define scw(x)          scanf("%I64d",&x)
#define sci(x)          scanf("%d",&x)
#define sc2(x,y)        scanf("%lld %lld",&x,&y)
#define sc3(x,y,z)      scanf("%lld %lld %lld",&x,&y,&z)
#define Found(a, b)     a.find(b) != a.end()
// bool operator< (const node& sx) const { return sx.val < val; }
//set<ll,greater<ll> >st;
//priority_queue<ll , vector<ll> , greater<ll> >
template<class T>inline bool read(T &x){ int c=getchar();int sgn=1;
  while(~c&&c<'0'|c>'9'){if(c=='-')sgn=-1;c=getchar();}
  for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar())x=x*10+c-'0';x*=sgn;return ~c;
}
const ll N = 10005;
const ll MOD = 1e9+7;
bitset<N>bs[N], ans;
vector<ll>v[N];
int main(){
    //fread;
    ll n = II, q = II;
    rep1(i,n){
        bs[i][0] = 1;
    }
    while(q--){
        ll l = II, r = II, x = II;
        rrep(i,l,r) bs[i] |= (bs[i] << x);
    }
    rep1(i,n) ans |= bs[i];
    ll c = 0;
    rep1(i,n) if(ans[i]) ++c;
    pfi(c),ln;
    rep1(i,n) if(ans[i]) pfi(i),sp;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

#define fread           freopen("input.txt","r",stdin)
#define fwrite          freopen("output.txt","w",stdout)
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define memo(ara,val)   memset(ara,val,sizeof(ara))
#define II              ( { int a ; read(a) ; a; } )
#define LL              ( { ll a ; read(a) ; a; } )
#define DD              ({double a; scanf("%lf", &a); a;})
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              printf("\n")
#define sc(x)           scanf("%lld",&x)
#define scw(x)          scanf("%I64d",&x)
#define sci(x)          scanf("%d",&x)
#define sc2(x,y)        scanf("%lld %lld",&x,&y)
#define sc3(x,y,z)      scanf("%lld %lld %lld",&x,&y,&z)
#define Found(a, b)     a.find(b) != a.end()
// bool operator< (const node& sx) const { return sx.val < val; }
//set<ll,greater<ll> >st;
//priority_queue<ll , vector<ll> , greater<ll> >
template<class T>inline bool read(T &x){ int c=getchar();int sgn=1;
  while(~c&&c<'0'|c>'9'){if(c=='-')sgn=-1;c=getchar();}
  for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar())x=x*10+c-'0';x*=sgn;return ~c;
}
const ll N = 10005;
const ll MOD = 1e9+7;
bitset<N>bs, ans;
vector<ll>v[N];
int main(){
    //fread;
    ll n = LL, q = LL;
    while(q--){
        ll l = LL, r = LL, x = LL;
        rrep(i,l,r) v[i].eb(x);
    }
    rep1(i,n){
        bs&=0;
        bs[0] = 1;
        for(ll y : v[i]){
            bs |= (bs << y);
        }
        ans|=bs;
    }
    ll c = 0;
    rep1(i,n) if(ans[i]) ++c;
    pf(c),ln;
    rep1(i,n) if(ans[i]) pf(i),sp;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef int ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

#define fread           freopen("input.txt","r",stdin)
#define fwrite          freopen("output.txt","w",stdout)
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define memo(ara,val)   memset(ara,val,sizeof(ara))
#define II              ( { int a ; read(a) ; a; } )
#define LL              ( { ll a ; read(a) ; a; } )
#define DD              ({double a; scanf("%lf", &a); a;})
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              printf("\n")
#define sc(x)           scanf("%lld",&x)
#define scw(x)          scanf("%I64d",&x)
#define sci(x)          scanf("%d",&x)
#define sc2(x,y)        scanf("%lld %lld",&x,&y)
#define sc3(x,y,z)      scanf("%lld %lld %lld",&x,&y,&z)
#define Found(a, b)     a.find(b) != a.end()
// bool operator< (const node& sx) const { return sx.val < val; }
//set<ll,greater<ll> >st;
//priority_queue<ll , vector<ll> , greater<ll> >
template<class T>inline bool read(T &x){ int c=getchar();int sgn=1;
  while(~c&&c<'0'|c>'9'){if(c=='-')sgn=-1;c=getchar();}
  for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar())x=x*10+c-'0';x*=sgn;return ~c;
}
const ll N = 10005;
const ll MOD = 1e9+7;
bitset<N>ans;
vector<ll>v[N*4];
void update(ll node, ll l, ll r, ll a, ll b, ll val){
     if(l > b || r < a) return;
     if(l >= a && r<=b){
         v[node].eb(val); return;
     }
     ll mid = (l+r) >> 1;
     update(node<<1, l, mid, a, b, val);
     update(node<<1|1, mid+1, r, a, b, val);
}
void query(ll node, ll l, ll r, bitset<N>bs){
     bitset<N>curr = bs;
     for(ll y: v[node]){
        curr |= (curr<<y);
     }
     if(l==r){
         ans|=curr; return;
     }
     ll mid = (l+r) >> 1;
     query(node<<1, l, mid, curr);
     query(node<<1|1, mid+1, r, curr);
}
int main(){
    //fread;
    bitset<N>bs;
    bs[0] = 1;
    ll n = II, q = II;
    while(q--){
        ll l = II, r = II, x = II;
        update(1, 1, n, l, r, x);
    }
    query(1, 1, n, bs);
    ll c = 0 ;
    rep1(i,n) if(ans[i]) ++c;
    pfi(c),ln;
    rep1(i, n) if(ans[i]) pfi(i),sp;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef int ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

#define fread           freopen("input.txt","r",stdin)
#define fwrite          freopen("output.txt","w",stdout)
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define memo(ara,val)   memset(ara,val,sizeof(ara))
#define II              ( { int a ; read(a) ; a; } )
#define LL              ( { ll a ; read(a) ; a; } )
#define DD              ({double a; scanf("%lf", &a); a;})
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              printf("\n")
#define sc(x)           scanf("%lld",&x)
#define scw(x)          scanf("%I64d",&x)
#define sci(x)          scanf("%d",&x)
#define sc2(x,y)        scanf("%lld %lld",&x,&y)
#define sc3(x,y,z)      scanf("%lld %lld %lld",&x,&y,&z)
#define Found(a, b)     a.find(b) != a.end()
// bool operator< (const node& sx) const { return sx.val < val; }
//set<ll,greater<ll> >st;
//priority_queue<ll , vector<ll> , greater<ll> >
template<class T>inline bool read(T &x){ int c=getchar();int sgn=1;
  while(~c&&c<'0'|c>'9'){if(c=='-')sgn=-1;c=getchar();}
  for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar())x=x*10+c-'0';x*=sgn;return ~c;
}
const ll N = 10005;
const ll MOD = 1e9+7;
bitset<N>bs, ans;
vector<ll>v[N];
int main(){
    //fread;
    ll n = II, q = II;
    while(q--){
        ll l = II, r = II, x = II;
        rrep(i,l,r) v[i].eb(x);
    }
    rep1(i,n){
        bs&=0;
        bs[0] = 1;
        for(ll y : v[i]){
            bs |= (bs << y);
        }
        ans|=bs;
    }
    ll c = 0;
    rep1(i,n) if(ans[i]) ++c;
    pfi(c),ln;
    rep1(i,n) if(ans[i]) pfi(i),sp;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

iii query[10000];
bitset<10001> chk;
set<int> to[10001],MIN[10001];
int main() {
	int n, q;
	scanf("%d%d", &n, &q);
	fup(i, 0, q - 1, 1)
	{
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		query[i] = iii(x, y, z);
	}
	sort(query, query + q);
	set<int> pq;
	MIN[0].insert(INF);
	fup(i, 0, q - 1, 1)
	{
		int x, y, z;
		tie(x, y, z) = query[i];
		while (!pq.empty() && *pq.begin() < x)
		{
			int t = *pq.begin();
			for (int next : to[t])
			{
				if (MIN[next].find(t) != MIN[next].end())MIN[next].erase(MIN[next].find(t));
			}
			pq.erase(pq.begin());
		}
		fdn(k, 10000, z, 1)
		{
			for (int x : MIN[k - z])
			{
				int tt = min(x, y);
				MIN[k].insert(tt);
				to[tt].insert(k);
			}
		}
		fup(i, 1, n, 1)if (!MIN[i].empty())chk[i] = 1;
	}
	Vi ans;
	fup(i, 1, n, 1)if (chk[i])ans.push_back(i);
	printf("%d\n", ans.size());
	for (int x : ans)printf("%d ", x);
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };
int DX[] = { 2,2,1,1,-1,-1,-2,-2 }, DY[] = { 1,-1,2,-2,2,-2,1,-1 };

bitset<10001> t[32768];
Vi v[32768];
void upd(int node, int S, int E, int l, int r, int x)
{
	if (l > r)return;
	if (S == l && E == r)
	{
		v[node].push_back(x);
		return;
	}
	int M = (S + E) >> 1;
	upd(node * 2, S, M, l, min(r,M), x);
	upd(node * 2 + 1, M + 1, E, max(l,M+1), r, x);
}
void solve(int node, int S, int E)
{
	t[node][0] = 1;
	if (S != E)
	{
		int M = (S + E) >> 1;
		solve(node * 2, S, M);
		solve(node * 2 + 1, M + 1, E);
		t[node] = t[node * 2] | t[node * 2 + 1];
	}
	for (int x : v[node])t[node] |= (t[node]) << x;
}
int main() {
	int n, q;
	scanf("%d%d", &n, &q);
	fup(i, 0, q - 1, 1)
	{
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		upd(1, 1, n, x, y, z);
	}
	solve(1, 1, n);
	Vi ans;
	fup(i, 1, n, 1)
		if (t[1][i])ans.push_back(i);
	printf("%d\n", ans.size());
	for (int x : ans)printf("%d ", x);
}