#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()
{
    ll n,k;
    ll mod = 998244353;
    cin>>n>>k;
    bool visit[n + 1];
    for(int i = 0;i<=n;i++)
        visit[i] = false;
    fi(i,k)
    {
        ll x,y;
        cin>>x>>y;
        f(j,x, y + 1)
        {
            visit[j] = true;
        }
    }
    ll dp[n + 1] = {0};
    dp[0] = 0;
    dp[1] = 1;
    for(ll i =2;i<=n;i++)
    {
        for(ll j = 1;j<i;j++)
        {
            if(visit[j])
            {
                dp[i] = (dp[i]%mod + dp[i - j]%mod)%mod;
            }
        }
    }
    cout<<dp[n];
}
