#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, k, mod = 998244353;
  cin >> n >> k;
  vector<int> s;
  for (int i = 0; i < (int)(k); i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j < (int)(r + 1); j++) s.push_back(j);
  }
  sort(s.begin(), s.end());
  vector<bool> seen(n + 1, false);
  vector<ll> dp(n + 1);
  dp[1] = 1;
  seen[1] = 1;
  bool f = false;
  for (int i = 1; i < (int)(n + 1); i++) {
    for (int j = 0; j < (int)(s.size()); j++) {
      if (i + s[j] > n) {
        break;
        if (j == 0) f = true;
      }
      if (seen[i] == 0) continue;
      dp[i + s[j]] += dp[i];
      dp[i + s[j]] %= mod;
      seen[i + s[j]] = 1;
    }
    if (f) break;
  }
  cout << dp[n] << endl;
}
