#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > vc;
map<long long, long long> mp;
long long rec(long long n) {
  if (n == 0) {
    return 0;
  }
  if (mp.count(n)) {
    return mp[n];
  }
  long long ans = 0;
  for (long long i = 0; i < vc.size(); i++) {
    for (long long j = vc[i].first; j <= vc[i].second; j++) {
      if (n == j) {
        ans = (ans + 1) % 998244353;
      } else if (n > j) {
        long long h = 0;
        if (mp.count(n - j)) {
          h = mp[n - j];
        } else {
          h = rec(n - j);
          mp[n - j] = h;
        }
        ans = (ans + h) % 998244353;
      } else {
        break;
      }
    }
  }
  return mp[n] = ans % 998244353;
}
int main() {
  long long n, k;
  cin >> n >> k;
  while (k--) {
    long long x, y;
    cin >> x >> y;
    vc.push_back({x, y});
  }
  cout << rec(n - 1) << endl;
}
