#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
const int N = 2e5+ 2, mod = 998244353;

void add(int& a, int b){
    if ((a += b) >= mod) a -= mod;
}


void solve() {
    int n, k;
    cin >> n >> k;
    vector<pii> p(k);
    for(int i = 0; i < k; i++) {
        cin >> p[i].first >> p[i].second;
    }
    vector<int> sum(n + 1);
    dp[1] = 1;
    for(int i = 2; i < n; i++) {
        ll curr = 0;
        for(int j = 0; j < k; j++) {
            if(v[j].first >= i) {
                continue;
            }
            int l = max(1, i - v[j].second);
            int r = i - v[j].first;
            curr += sum[r] - sum[l - 1];
        }
        curr %= mod;
        if(curr < 0) {
            curr += mod;
        }
        sum[i] = (sum[i - 1] + curr) % mod;
    }
    ll ans = sum[n] - sum[n - 1];
    if(ans < 0) {
        ans += mod;
    }
    cout << ans;   
}    


int main() {
  int tt = 1;
  // cin >> tt;
  for (int tc = 1; tc <= tt; tc++) {
    // cout << "Case #:" << tc << " ";
    solve();
  }
}