#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MOD = 998244353;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  long long n, k;
  cin >> n >> k;
  map<long long, long long> m;
  vector<long long> d;
  for (long long i = 0; i < (k); i++) {
    long long l, r;
    cin >> l >> r;
    for (long long i = l; i < (r + 1); i++) m[i]++;
  }
  for (auto x : m) d.push_back(x.first);
  vector<long long> dp(3 * n, 0);
  dp[1] = 1;
  for (long long i = 1; i < (n); i++) {
    for (long long j = 0; j < (d.size()); j++) {
      dp[i + d[j]] += dp[i];
      dp[i + d[j]] %= MOD;
    }
  }
  cout << dp[n] << endl;
}
