#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 998244353
#define vlli vector<ll>
#define vi vector<ll>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< ll, ll> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define prll(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;
const ll N = 1e5+2;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

vlli v;

ll countWays(ll n) 
{ 
    ll count[n + 1] = {};
      
    // base case 
    count[0] = 1; 
      
    // count ways for all values up  
    // to 'N' and store the result 
    for (ll i = 1; i <= n; i++) 
        for (ll j = 0; j < v.size(); j++) 
  
            // if i >= arr[j] then 
            // accumulate count for value 'i' as 
            // ways to form value 'i-arr[j]' 
            if (i >= v[j]) {
                count[i] += count[i - v[j]]; 
                count[i]%=mod;
            }

      
    // required number of ways  
    return count[n];  
      
} 


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll n, k;
    cin>>n>>k;
    ll a[n+1] = {};
    ll l, r;
    forn(i, 0, k){
        cin>>l>>r;
        l--, r--;
        a[l]++;
        a[r+1]--;
    }
    forn(i, 1, n){
        a[i]+=a[i-1];
    }
    
    forn(i, 0, n){
        if(a[i]>0){
            v.pb(i+1);
        }
    }
    // prll(v, 0, v.size());
    // cout<<endl;

    cout<<countWays(n-1)<<endl;
    
}