#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long mod = 998244353;
void test_case() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (; l <= r; l++) {
      s.insert(l);
    }
  }
  vector<int> coins = vector<int>(s.begin(), s.end());
  vector<long long> dp(n + 1, 0);
  dp[n] = 1;
  for (int i = n - 1; i >= 1; i--) {
    int mx = n + 1 - i;
    int low = upper_bound(coins.begin(), coins.end(), mx) - coins.begin();
    low--;
    for (int j = 0; j <= low; j++) {
      if (i + coins[j] <= n) {
        dp[i] += dp[i + coins[j]];
      }
    }
    dp[i] %= mod;
  }
  cout << dp[1] << endl;
}
int main() {
  int t = 1;
  for (int i = 0; i < t; i++) test_case();
  return 0;
}
