#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long N, K;
vector<long long> memo(200010, -1);
vector<long long> s;
long long solve(long long now) {
  if (now < s.at(0)) {
    return 0;
  }
  if (now == s.at(0)) {
    return memo.at(now) = 1;
  }
  if (memo.at(now) != -1) {
    return memo.at(now) = 0;
  }
  long long res = 0;
  for (long long i = 0; i < (long long)(s.size()); i++) {
    res += solve(now - s.at(i));
    res %= MOD;
  }
  return memo.at(now) = res;
}
int main() {
  cin >> N >> K;
  for (long long i = 0; i < (long long)(K); i++) {
    long long r, l;
    cin >> r >> l;
    for (long long j = r; j < (long long)(l + 1); j++) {
      s.push_back(j);
    }
  }
  sort(s.begin(), s.end());
  long long ans = solve(N);
  while (ans < 0) {
    ans += MOD;
  }
  cout << ans << endl;
}
