#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 998244353;
int n;
int k;
int mem[N];
bool did[N];
vector<int> v;
int go(int poi) {
  if (poi == n) return 1;
  if (poi > n) return 0;
  int& ret = mem[poi];
  if (~mem[poi]) return mem[poi];
  ret = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] + poi <= n) {
      ret = ret + go(poi + v[i]);
      ret %= mod;
    } else {
      break;
    }
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  memset(mem, -1, sizeof mem);
  for (int i = 1; i <= k; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    for (int i = l; i <= r; i++) v.push_back(i);
  }
  sort(v.begin(), v.end());
  for (int i = n; i > 1; i--) go(i);
  printf("%d\n", go(1));
}
