#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int dx8[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[] = {0, -1, 0, 1, 1, -1, 1, -1};
vector<long long> dp, j;
long long solve(long long pos) {
  if (pos == dp.size() - 1) return 1;
  if (dp[pos] != -1) return dp[pos];
  long long ans = 0;
  for (auto x : j) {
    if (x + pos >= dp.size()) break;
    ans = (ans % 998244353 + solve(x + pos) % 998244353) % 998244353;
  }
  dp[pos] = ans;
  return ans;
}
void solve() {
  long long n;
  cin >> n;
  dp.clear();
  dp.resize(n, -1);
  j.clear();
  long long k;
  cin >> k;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j1 = x; j1 <= y; j1++) j.push_back(j1);
  }
  sort(j.begin(), j.end());
  cout << solve(0) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
