#include <bits/stdc++.h>
using namespace std;
long long powm(long long base, long long exp, long long mod = 998244353) {
  long long ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % mod;
    exp >>= 1, base = (base * base) % mod;
  }
  return ans;
}
vector<long long> dp;
static long long counts;
long long found(vector<long long>& a, long long i, long long n) {
  if (i > n) return 0;
  if (dp[i] != -1) return dp[i];
  if (i == n) return 1;
  long long paths = 0;
  for (long long j = 0; j < a.size(); j++) {
    paths = (paths % 998244353 + found(a, i + a[j], n) % 998244353) % 998244353;
  }
  return dp[i] = paths % 998244353;
}
int32_t main() {
  long long n, k;
  cin >> n >> k;
  unordered_set<long long> s;
  for (long long i = 0; i < k; i++) {
    long long a, b;
    cin >> a >> b;
    for (long long j = a; j <= b; j++) s.insert(j);
  }
  vector<long long> a(s.begin(), s.end());
  dp.assign(n + 2, -1);
  cout << found(a, 1, n) % 998244353 << endl;
}
