#include <iostream>

using namespace std;
typedef long long ll;
ll dp[200010] = {},sum[200010] = {},l[20],r[20],mod = 998244353;
int main(){
    int i,j,n,k; cin >> n >> k;
    for(i=0;i<k;i++) cin >> l[i] >> r[i];
    dp[1] = 1; sum[1] = 1;
    for(i=2;i<=n;i++){
        for(j=0;j<k;j++){
            (dp[i] += (sum[max(0LL,i - l[j])] - sum[max(0LL,i - r[j] - 1)] + mod)%mod) %= mod;
        }
        sum[i] = (sum[i - 1] + dp[i])%mod;
    }
    cout << dp[n] << endl;
}