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

#define int long long
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)

int N, K;
int L[11], R[11];
int dp[200010];
int mod = 998244353;

signed main()
{
    cin >> N >> K;
    rep(i, K)cin >> L[i] >> R[i];

    dp[1] = 1;
    for(int i = 2; i <= N; i++)
    {
        int diff = 0;
        rep(j, K)
        {
            diff = (diff + dp[max(0LL, i - L[j])] - dp[max(0LL, i - R[j] - 1)]  + mod) % mod;
        }
        dp[i] = (dp[i - 1] + diff) % mod;
    }

    cout << (dp[N] - dp[N - 1] + mod) % mod << endl;

    return 0;
}
