#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> wa(N + 1, 0);
  wa.at(1) = 1;
  vector<P> p(K);
  int x, y;
  const int mod = 998244353;
  for (int i = 0; i < (K); ++i) {
    cin >> x >> y;
    p.at(i) = make_pair(x, y);
  }
  for (int i = 1; i < N; i++) {
    int sum = 0;
    for (int j = 0; j < (K); ++j) {
      int r = max(i - (p.at(j).first) + 1, 0);
      int l = max(i - (p.at(j).second), 0);
      sum += wa.at(r) - wa.at(l);
      sum %= mod;
    }
    wa.at(i + 1) = wa.at(i) + sum;
    wa.at(i + 1) %= mod;
  }
  cout << wa.at(N) - wa.at(N - 1) << endl;
  return 0;
}
