#include <bits/stdc++.h>
 
#define int long long
#define MOD 998244353
 
using namespace std;
 
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V)
        os << v << " ";
    os << "]";
    return os;
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class T> ostream &operator<<(ostream &os, multiset<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
    os << "{ ";
    for (auto m : M)
        os << "(" << m.first << ":" << m.second << ") ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}

int num[1000005] = {0};

void sieveMinPrime() {
    for(int i = 1;i <= 1000005; i++) {
        num[i] = i;
    }
    for(int i = 2;i <= 1000005; i++) {
        if(num[i] != i) {
            continue;
        }
        for(int j = i * i; j <= 1000005; j += i) {
            if(num[j] == j) num[j] = i;
        }
    }
}


void solve() {
    int n, k;
    cin >> n >> k; 
    int dp[n + 1] = {0};
    dp[1] = 1;
    set<int> seg;
    for(int i = 0; i < k; i++) {
        int l, r;
        cin >> l >> r;
        for(int i = l; i <= r; i++) {
            seg.insert(i);
        }
    }
    for(int i = 1; i < n; i++) {
        for(auto itr : seg) {
            if(i + itr <= n) dp[i + itr] = (dp[i + itr] + dp[i]) % MOD;
        }
    }

    cout << dp[n];
}


int32_t main() {
    int t;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    return 0;
}