#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, k, mod = 998244353;
  set<long long> s;
  cin >> n >> k;
  while (k--) {
    long long l, r;
    cin >> l >> r;
    for (long long i = l; i <= r; i++) {
      s.insert(i);
    }
  }
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  for (long long i = 1; i < n; i++) {
    for (auto j : s) {
      if (j + i > n) break;
      dp[i + j] += dp[i];
      dp[i + j] += mod;
      dp[i + j] %= mod;
    }
  }
  cout << dp[n] << '\n';
}
