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