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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
#define fileio freopen("template.in", "r", stdin), freopen("template.out", "w", stdout);
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;

int main() {
    fastio;
    //fileio;
        
    int n;
    int k;
    cin >> n >> k;
    vi S;
    FOR(i, 0, k) {
        int a, b;
        cin >> a >> b;
        FOR(j, a, b+1) {S.pb(j);}
    }
    sort(all(S));
    ll ways[n] = {};
    ways[0] = 1;
    FOR(i, 0, n) {
        ways[n-1] %= 998244353;
        FOR(j, 0, S.size()) {
            if (i+1 + S[j] <= n) {
                ways[i+S[j]] += ways[i];
            } else {
                break;
            }
        }
    }
    ways[n-1] %= 998244353;
    cout << ways[n-1] << "\n";
    return 0;
}
