#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define int long long
#define float long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'
#define pii pair<int, int>
#define tii tuple<int, int, int>
#define min3(a,b,c) min(a, min(b, c))
#define max3(a,b,c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

signed main()
{
 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n,k; cin>>n>>k;
    pii arr[k];
    for(int i=0;i<k;i++) cin>>arr[i].ff>>arr[i].ss;
    int dp[n+1]={0},ways[n+1],ans=0; 
	dp[1]=1; dp[2]=-1;
	for(int i=1;i<=n;i++){
		ans=(ans+dp[i]+mod)%mod;
		ways[i]=ans;
		for(pii it : arr){
			if(i+it.ff<=n) dp[i+it.ff]+=ans;
			if(i+it.ss+1<=n) dp[i+it.ss+1]-=ans;
		}
	}
	cout<<ans<<endl;

}