#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 200010;
const LL mod = 998244353;

struct Line
{
    int l, r;
}a[N];

LL f[N], s[N];
int n, k;

int main()
{
    scanf("%d%d", &n, &k);

    for (int i = 1; i <= k; i ++ ) scanf("%d%d", &a[i].l, &a[i].r);

    f[1] = 1;
    s[1] = 1;
    for (int i = 2; i <= n; i ++ )
    {
        for (int j = 1; j <= k; j ++ )
        {
            f[i] = (f[i] + s[max(0, i - a[j].l)] - s[max(0, i - a[j].r - 1)]) % mod;
        }
        s[i] = (s[i - 1] + f[i]) % mod;
    }

    printf("%lld\n", (f[n] + mod) % mod);

    return 0;
}