#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> v;
    long long pre[n + 1];
    for (long long i = 0; i <= n; ++i) pre[i] = 0;
    for (long long i = 0; i < k; ++i) {
      long long u, v;
      cin >> u >> v;
      pre[u]++;
      pre[v + 1]--;
    }
    for (long long i = 1; i <= n; ++i) {
      pre[i] += pre[i - 1];
    }
    for (long long i = 1; i <= n; ++i) {
      if (pre[i]) v.push_back(i);
    }
    long long len = (long long)v.size();
    vector<long long> dp(n, 0);
    dp[0] = 1;
    for (long long i = 1; i <= n - 1; ++i) {
      for (long long j = 0; j < len; ++j) {
        if (i - v[j] >= 0) {
          dp[i] += dp[i - v[j]];
          dp[i] = dp[i] % mod;
        }
      }
    }
    cout << dp[n - 1] << "\n";
  }
}
