#include<bits/stdc++.h>
#define fr(i,c,b) for(int i=c;i<b;i++)
#define frl(i,c,b) for(ll i=c;i<b;i++)
#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl printf("\n")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define MAX 100001
#define M 998244353
#define pb push_back

typedef long long int ll;

using namespace std;




int main()
{
   si(n); si(k);
   ll a[n+1];
   fr(i,0,n+1)  a[i]=i;
   unordered_set<ll> jump;
   while(k--)
   {
       si(x); si(y);
       for(int i=x;i<=y;i++)
       {
           jump.insert(a[i]);
       }
   }
    vector<ll> v;
    for(auto i:jump)
    {
        v.pb(i);
    }
    
    ll dp[n+1]={0};
    dp[n]=0;
    
    for(int i=n-1;i>=1;i--)
    {
        for(auto j:v)
        {
            if(j+i==n)
                dp[i]=(dp[i]+1);
            else if(j+i<n)
            {
                dp[i]=(dp[i]+dp[i+j]);
            }
            if(dp[i]>=M) dp[i]=dp[i]-M;
        }
    }
    if(dp[1]>=M) dp[1]-=M;
    
    pll(dp[1]);
    
}