#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, t;
	cin >> n >> t;

	vector<int>jumps;
	while (t--)
	{	int a, b;
		cin >> a >> b;
		for (int i = a; i <= b; i++)
		{
			jumps.pb(i);
		}
	}



	int dp[n + 1] = {0};
	dp[0] = 0;
	dp[1] = 1;

	int m = jumps.size();
	for (int i = 2; i <= n; i++)
	{	int res = 0;
		for (int j = 0; j < m; j++)
		{	if (i - jumps[j] >= 0)
			{	res += dp[i - jumps[j]];
				res %= mod;

			}

		}
		dp[i] = res;

	}
	cout << dp[n] << endl;


	return 0;
}
