#include <bits/stdc++.h>
using namespace std;
long long n, k, dp[300001], mod = 998244353;
set<long long> s;
long long f(long long x) {
  if (dp[x]) return dp[x];
  long long h = 0;
  for (auto i : s) {
    if (x - i <= 0) break;
    h += f(x - i);
    h += mod;
    h %= mod;
  }
  return dp[x] = h;
}
signed main() {
  cin >> n >> k;
  while (k--) {
    long long l, r;
    cin >> l >> r;
    for (long long i = l; i <= r; i++) {
      s.insert(i);
    }
  }
  dp[1] = 1;
  cout << f(n) << '\n';
}
