#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define print(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int bexp(int a, int b, int mod)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

const int N = 100010;
const int mod = 998244353;

struct comp {
    bool operator() (const pair<int, int> a, const pair<int, int> b) const
    {
        return a.ss > b.ss;
    }
};

int32_t main() 
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int n, k;
    cin >> n >> k;

    int l, r;
    vector<int> p;
    for (int i = 0; i < k; ++i)
    {
        cin >> l >> r;

        for (int j = l; j <= r; ++j) {
            p.pb(j);
        }
    }

    sort(p.begin(), p.end());

    int dp[n] = {};

    dp[0] = 1;

    for (int i = 1; i < n; ++i) {
        for (int k : p) {
            if (i - k < 0) {
                break;
            }
            dp[i] = (dp[i] + dp[i - k]) % mod;
        }
    }


    cout << dp[n - 1] << endl;
    return 0;
}