#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
const int mod = 998244353;
void __print() { cerr << "]\n"; }
template <typename T, typename... V>
void __print(T t, V... v) {
  cerr << t;
  if (sizeof...(v)) cerr << ", ";
  __print(v...);
}
i64 dp[300000];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  vector<int> steps;
  while (k--) {
    int l, r;
    scanf("%d%d", &l, &r);
    for (int i = l; i <= r; i++) steps.push_back(i);
  }
  dp[1] = 1;
  sort(steps.begin(), steps.end());
  int sz = steps.size();
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < sz; j++) {
      if (i + steps[j] > n) break;
      dp[i + steps[j]] += dp[i];
      dp[i + steps[j]] %= mod;
    }
  }
  printf("%lld\n", dp[n]);
}
