#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long long MOD = 998244353;
template <class Q>
void clearQueue(Q& q) {
  q = Q();
}
void solve() {
  long long n, k;
  cin >> n >> k;
  map<long long, long long> mp;
  vector<long long> v;
  for (long long i = 1; i <= k; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j = x; j <= y; j++) {
      if (mp[j] == 0) {
        v.push_back(j);
        mp[j]++;
      }
    }
  }
  sort(v.begin(), v.end());
  long long dp[n];
  memset(dp, 0, sizeof dp);
  dp[0] = 1;
  for (long long i = 1; i < n; i++) {
    long long ans = 0;
    for (long long j = 0; j < n; j++) {
      if (v[j] <= i) {
        ans = (ans + dp[i - v[j]]) % MOD;
      } else {
        break;
      }
    }
    dp[i] = ans;
  }
  cout << dp[n - 1];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T = 1;
  while (T--) {
    solve();
  }
}
