#include <bits/stdc++.h>
using namespace std;
long long dp[1000005];
vector<long long> v;
long long n;
long long go(long long idx) {
  if (idx > n) return 0;
  if (idx == n) return 1;
  long long &ans = dp[idx];
  if (ans != -1) return ans;
  ans = 0;
  for (auto &x : v)
    if (idx + x <= n)
      ans = (ans + go(idx + x)) % 998244353;
    else
      break;
  return ans;
}
void solve() {
  cin >> n;
  memset(dp, -1, sizeof dp);
  long long k;
  cin >> k;
  while (k--) {
    long long l, r;
    cin >> l >> r;
    for (long long i = l; i <= r; ++i) v.push_back(i);
  }
  sort(v.begin(), v.end());
  cout << go(1) << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T = 1;
  for (long long i = 1; i <= T; ++i) {
    solve();
  }
  return 0;
}
