#include <bits/stdc++.h>

const int p = 998244353;

int main()
{
    int n, k;
    std::cin >> n >> k;

    int *l, *r;
    l = new int[k];
    r = new int[k];
    for (int i = 0; i < k; ++i)
        std::cin >> l[i] >> r[i];

    int *f, *s;
    f = new int[n + 1]();
    s = new int[n + 1]();
    f[1] = 1;
    s[1] = 1;
    for (int i = 2; i <= n; ++i)
    {
        for (int j = 0; j < k; ++j)
            f[i] = ((f[i] + s[std::max(i - l[j], 0)] - s[std::max(i - r[j] - 1, 0)]) % p + p) % p;
        s[i] = (s[i - 1] + f[i]) % p;
    }
    std::cout << f[n] << std::endl;
    return 0;
}