/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-09-19 20:27:56
 * @LastEditTime: 2020-09-19 20:41:34
 * @FilePath: \VSC\C++\Practice\AC abc179 D.cpp
 */
#include <bits/stdc++.h>
using namespace std;
#define Mod 998244353
#define int long long

int n, k;
int dp[200005];
int stp[200005];
int index = 0;
signed main()
{
    scanf("%lld%lld", &n, &k);
    register int i, j;

    for (i = 1; i <= k; ++i) {
        int x, y;
        scanf("%lld%lld", &x, &y);
        for (j = x; j <= y; ++j)
            stp[++index] = j;
    }

    dp[1] = 1;
    for (i = 2; i <= n; ++i) {
        for (j = 1; j <= index; ++j) {
            if (i - stp[j] >= 1)
                dp[i] = (dp[i] + dp[i - stp[j]]) % Mod;
        }
    }

    printf("%lld\n", dp[n]);
    return 0;
}