#include <bits/stdc++.h>
const int m = 998244353;
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n, k, a, b;
  scanf("%lld%lld", &n, &k);
  set<long long> s;
  while (k--) {
    scanf("%lld%lld", &a, &b);
    for (int i = a; i <= b; i++) s.insert(i);
  }
  vector<long long> r(n + 1);
  r[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int x : s) {
      if (i - x < 0) break;
      r[i] += r[i - x];
      r[i] %= m;
    }
  }
  printf("%lld", r[n]);
}
