#include <bits/stdc++.h>
using namespace std;
const long long maxS = 2e5 + 10;
long long MOD = 998244353;
long long N, K;
long long DP[maxS];
set<pair<long long, long long>> SET;
long long go(long long pos) {
  if (pos == N) return 1;
  if (pos > N) return 0;
  if (DP[pos] != -1) return DP[pos];
  long long ans = 0;
  for (auto it : SET) {
    for (long long i = it.first; i <= it.second; i++)
      ans = (ans + go(pos + i)) % MOD;
  }
  return DP[pos] = ans;
}
void code_idhr_h() {
  cin >> N >> K;
  while (K--) {
    long long x, y;
    cin >> x >> y;
    SET.insert({x, y});
  }
  memset(DP, -1, sizeof DP);
  cout << go(1);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long T = 1;
  for (long long t = 1; t <= T; t++) {
    code_idhr_h();
  }
  return 0;
}
