#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 998244353;
const int N = 200005;

int a[N], b[N];
LL f[N], c[20];
int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
    }
    f[1] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            c[j] += (i - a[j] >= 1 ? f[i - a[j]] : 0) - (i - b[j] - 1 >= 1 ? f[i - b[j] - 1] : 0);

            f[i] = (f[i] + c[j]) % mod;
        }
    }
    cout << (f[n] + mod) % mod << endl;
    return 0;
}
