#include <bits/stdc++.h>
using namespace std;
//long long int i,j,k,n,m,a,b,c,d,p,q,r,l,t=1;
//long long int sum,counted,ans;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
void sample()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
long long int* read(long long int n)
{
    long long int* arr=new long long int[n];

    for(int i=0;i<n;i++)
        cin>>arr[i];

    return arr;
}
long long int countDivisors(long long int n) 
{ 
    long long int cnt = 0; 
    for (long long int i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            // If divisors are equal, 
            // count only one 
            if (n / i == i) 
                cnt++; 
  
            else // Otherwise count both 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 


void solve()
{
    long long int n,i,j,k,ans,m,o;

    cin>>n>>k;

    //long long int ar[n];

    //long long int* ar=read(n);
    long long int ar[n+2]={0};

    set<long long int> s;
    vector<long long int> v;

    for(i=0;i<k;i++)
    {
        int a,b;
        cin>>a>>b;
        ar[a]++;
        ar[b+1]--;
    }


    bool ok=0;
    for(i=1;i<=n;i++)
    {
        if(ok)
        {
            if(ar[i]<0)
            {
                ok=0;
                continue;
            }
            s.insert(i);
            v.push_back(i);
            

        }
        else
        {
            if(ar[i]>0)
            {
                s.insert(i);
                v.push_back(i);
                ok=1;
            }
        }
    }

    sort(v.begin(), v.end());
    //reverse(v.begin(), v.end());

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

    dp[1]=1;

    for(i=2;i<=n;i++)
    {
        //cout<<i<<endl;
        for(auto j:v)
        {
            //cout<<j<<endl;
            if(j>=i)
                break;
            dp[i]=dp[i]+dp[i-j];
            dp[i]=dp[i]%((int)998244353);
        }
        //cout<<endl;
    }

   /* for(auto j:s)
        cout<<j<<" ";
    cout<<endl;*/

    /*for(auto j:v)
    {
        for(i=1;i<=n;i++)
        {

            dp[i]=dp[i]+dp[i-j];
            dp[i]=dp[i]%((int)998244353);
        }
    }*/



    cout<<dp[n]%((int)998244353);



    



    return;
}





int main()
{
    fast();
    sample();
    long long int i, j, k, n, m, a, b, c, d, p, q, r, l, t = 1;
    long long int sum, count = 0, ans = 0;

    //cin >> t;
    while (t--)
    {
        solve();

    }

    return 0;
}
