#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  int l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (; l <= r; l++) s.push_back(l);
  }
  sort(begin(s), end(s));
  vector<long long> cnt(n + 1, 0);
  cnt[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int d : s) {
      if (i + d < n + 1) {
        cnt[i + d] += cnt[i];
        cnt[i + d] %= MOD;
      } else
        break;
    }
  }
  cout << cnt[n] << endl;
  return 0;
}
