#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=200005;
const int mod = 998244353;
int dp[maxn],n,k,l[12],r[12];
int main()
{
    scanf("%d%d",&n,&k);
    for (int i = 0; i < k; i++)
        scanf("%d%d",l+i,r+i);
    dp[1]=1;
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < k; j++)
        {
            if (i + l[j] > n)
                continue;
            dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % mod;
            dp[min(i + r[j] + 1, n + 1)] = (dp[min(i + r[j] + 1, n + 1)] - dp[i] + mod) % mod;

        }
        if(i>1)
            dp[i+1]= (dp[i+1] + dp[i]) % mod;
    }
    printf("%d\n",dp[n]);
    return 0;
}