#include <bits/stdc++.h>
using namespace std;

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;
ll mods = 998244353;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n;
    int k;
    cin >> n >> k;
    vector<ll> s(k*2);
    ll l,r,lmin=n;
    rep(i,k){
        cin >> l >> r;
        s[i*2] = l;
        s[i*2+1] = r;
        lmin = min(l,min); 
    }
    vector<ll> tb(n+1,0);
    tb[1]=1;
    for(ll i=1;i<n-lmin;i++){
        if(tb[i]==0) continue;
        rep(j,k){
            l = s[j*2];
            r = s[j*2+1];
            rep(m,r-l+1){
                if(i+l+m>n) break;
                tb[i+l+m] += tb[i];
                if(tb[i+l+m]>mods) tb[i+l+m]%=mods;
            }
        }
    }
    print(tb[n]);
    return 0;
}
