#include <bits/stdc++.h>
using namespace std;
const int magic = 998244353;
int check(vector<int> tegoma, int nokori, int depth);
int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  vector<int> available;
  for (int i = 1; i <= K; i++) {
    int st, ed;
    cin >> st >> ed;
    for (int j = st; j <= ed; j++) {
      available.push_back(j);
    }
  }
  sort(available.begin(), available.end(), greater<int>());
  vector<int> nanko(available.size(), 0);
  ans = check(available, N - 1, 0);
  cout << ans % magic << endl;
  return 0;
}
int check(vector<int> tegoma, int nokori, int depth) {
  if (nokori == 0)
    return 1;
  else if (depth == tegoma.size())
    return 0;
  else
    return check(tegoma, nokori % tegoma.at(depth), depth + 1) % magic +
           check(tegoma, nokori, depth + 1) % magic;
}
