#include <bits/stdc++.h>

#define ll                  long long
#define ld                  long double
#define pb                  push_back
#define mp                  make_pair
#define fi                  first
#define se                  second
#define all(c)              (c).begin(),(c).end()
#define for0(i, n)          for (ll i = 0; i < n; ++i)
#define for1(i, n)          for (ll i = 1; i <= n;++i)
#define for2(i, n)          for (ll i = 1; i < n; ++i)
#define for3(i, k, n)       for (ll i = k; i < n; ++i)
#define input(a, i, n)      for (int i = 0; i < n; ++i) {cin >> a[i]; }
#define output(a, i, n)     for (int i = 0; i < n; ++i) {cout << a[i] << ' '; }
//cout.precision(12);

using namespace std;

int64_t TN = 1;

void solve()
{
    int64_t n, k;
    cin >> n >> k;
    vector <int64_t> v;
    set <int64_t> st;
    for (int i = 0; i < k; ++i) {
        cin >> a >> b;
        for (int j = a; j <= b; ++j) st.insert(j);
    }
    for (auto it : st) v.pb(it);
    vector <int64_t> cur(n + 1);
    cur[1] = 1;
    for (int i = 2; i <= n; ++i) {
        for (auto it : st) {
            if (i - it > 0) {
                cur[i] += cur[i - it];
            }
            else break;
        }
    }
    cout << cur[n] % 998244353;
}

int main()
{
    //cin >> TN;
    for (int i = 0; i < TN; ++i) {
        solve();
    }
    return 0;
}
