#include <bits/stdc++.h>
using namespace std;
long long int bit[200005], mod = 998244353;
void update(int ind, long long int val) {
  ind++;
  while (ind < 200005) {
    bit[ind] = (bit[ind] + val) % mod;
    ind += (ind) & (-ind);
  }
}
long long int getsum(int ind) {
  long long int sum = 0;
  ind++;
  while (ind > 0) {
    sum = (sum + bit[ind]) % mod;
    ind -= (ind) & (-ind);
  }
  return sum;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > pairs(k);
  for (auto &el : pairs) cin >> el.first >> el.second;
  int st = n + 10;
  for (int i = 0; i < k; i++) {
    bool fl = false;
    for (int j = pairs[i].first; j <= pairs[i].second; j++) {
      if ((n - 1) % j == 0) {
        update(j, 1);
        st = j + 1;
        fl = true;
        break;
      }
    }
    if (fl) break;
  }
  for (int i = st; i <= n; i++) {
    long long int sm = 0;
    for (auto el : pairs) {
      int r = max(i - el.second, 0);
      int l = max(i - el.first, 0);
      sm += getsum(l);
      sm -= getsum(r - 1);
      sm = (sm + mod + mod) % mod;
    }
    update(i, sm);
  }
  long long int ans = getsum(n);
  ans = (ans - getsum(n - 1) + mod + mod) % mod;
  cout << ans << endl;
  return 0;
}
