#include <bits/stdc++.h>
using namespace std;
vector<long long> s;
long long len = 0;
long long prime = 998244353;
long long flag[200019];
long long solve(long long n, long long cur_pos) {
  if (cur_pos > n) return 0;
  if (cur_pos == n) return 1;
  if (flag[cur_pos] != -1) return flag[cur_pos];
  long long res = 0;
  for (int i = 0; i < len; i++) {
    res = (res % prime + solve(n, cur_pos + s[i]) % prime) % prime;
  }
  flag[cur_pos] = res;
  return flag[cur_pos];
}
int main() {
  for (int i = 0; i < 200019; i++) {
    flag[i] = -1;
  }
  long long t, n, count = 0, m, k, l, r;
  scanf("%lld", &n), scanf("%lld", &k);
  for (long long i = 0; i < k; i++) {
    scanf("%lld", &l);
    scanf("%lld", &r);
    for (int i = l; i <= r; i++) s.push_back(i);
  }
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  len = s.size();
  cout << solve(n, 1) << endl;
  return 0;
}
