#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9 + 7;
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;
}
__attribute__((constructor)) void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}
set<int> si;
long long n, k;
long long memo[100010] = {-1};
long long solve(long long now) {
  long long rec = 0;
  bool ok = 0;
  if (now == 1) {
    rec = 1;
    return 1ll;
  }
  for (auto u : si) {
    if (now - u >= 1) {
      ok = 1;
      if (memo[now - u] != -1) {
        rec += memo[now - u] % MOD;
      } else {
        rec += solve(now - u) % MOD;
      }
      rec %= MOD;
    }
  }
  memo[now] = rec;
  return rec;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < (k); i++) {
    int l, r;
    cin >> l >> r;
    for (int j = (l); j < (r + 1); j++) {
      si.insert(j);
    }
  }
  memo[1] = 1;
  for (int i = 0; i < (100010); i++) {
    memo[i] = -1;
  }
  cout << solve(n) << endl;
  return 0;
}
