#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i,n) for( ll i=0 ; i<n ; i++ )
#define f(i, a, b) for( ll i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
#define MOD 1000000007

ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}
vector<ll> SieveOfEratosthenes(ll n,ll a)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    vector<ll>v;
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {

            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (ll p= a; p<=n; p++)
       if (prime[p])
          v.push_back(p);
    return v;
}
void permute(string a, int l, int r)
{
    // permutes string
    if (l == r)
    {
        cout<<a<<endl;
    }
    else
    {
        for (int i = l; i <= r; i++)
        {
            swap(a[l], a[i]);
            permute(a, l+1, r);
        }
    }
}

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>v;
    int mod = 998244353;
    fi(i,k)
    {
        int x,y;
        cin>>x>>y;
        f(j,x, y + 1)
        {
            v.push_back(j);
        }
    }
    int dp[n + 1] = {0};
    dp[0] = 0;
    dp[1] = 1;
    sort(v.begin(),v.end());
    vector<int>::iterator it;
    for(int i =2;i<=n;i++)
    {
        it = upper_bound(v.begin(),v.end(),i);
        int index  = it - v.begin();
        for(int j = 0;j<index;j++)
        {
            if(v[j]<i)
                dp[i] = (dp[i]%mod + dp[i - v[j]]%mod)%mod;

        }

    }
    cout<<dp[n];
}

