	#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 endl                "\n"
	#define loop(i,s,e)         for(int i=s;i<e;i++)
	#define int                 long long
	#define vi                  vector<int> 
	#define S(v)                sort(v.begin(),v.end())
	#define RS(v)               sort(v.rbegin(),v.rend())
	#define R(v)                reverse(v.begin(),v.end())
	#define mxpq(T)             priority_queue <T>
	#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
	#define prv(v)              for(auto &x : v)cout << x << " ";
	#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
	#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
	#define mp                  make_pair
	#define pii                 pair<int,int>
	#define mset(a,f)           memset(a , f , sizeof(a))
	#define pb                  push_back
	#define inf                 INT_MAX
	#define INF                 LLONG_MAX
	typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
	 
	const int N = 2e6 + 6;
	const int M = 998244353;
	int A[N];
	int dp[N];
	int n,k;
	map<int,int> mmp;

	int alpha(int i)
	{
	 	if(i == n)return 1;
	 	if(i > n)return 0;
	 	int &abs = dp[i];
	 	if(abs != -1)return abs;

	 	int ans = 0;

	 	for(auto &it : mmp)
	 	{
	 		ans =  (ans%M + alpha(i + it.ff)%M)%M;
	 		ans %= M;
	 	}

	 	return abs = ans%M;
	}

	void solve()
	{
		cin >> n >> k;

		map<int,int> m;

		loop(i,0,k)
		{
			int x, y;
			cin >> x >> y;
			loop(j,x,y+1)m[j]++;
			// mmp[x]++ , mmp[y]++;
		}
		for(auto &it : m)
		{
			if(it.ff < n)mmp[it.ff]++;
			else break;
		}
		mset(dp, -1);
		int ans = alpha(1);

		cout << ans;
	}			
	 
	int32_t main()
	{
	 
	cout<<fixed<<setprecision(16);
	 
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	 	
	 
	 	int t = 1;
	 	// cin >> t;
	 	while(t--)solve();
	  
	}