#include <bits/stdc++.h>
using namespace std;
int slv(int n, vector<int> &steps, vector<int> &ladder) {
  queue<int> q;
  q.push(1);
  ladder[1] = 0;
  while (!q.empty()) {
    int tp = q.front();
    q.pop();
    int val = tp;
    for (auto step : steps) {
      if (val + step <= n) {
        ladder[val + step] =
            (ladder[val + step] % (int)(998244353) + 1) % (int)(998244353);
        q.push(val + step);
      }
    }
  }
  return ladder[n];
}
void solve() {
  long long int n;
  cin >> n;
  ;
  long long int k;
  cin >> k;
  ;
  ;
  vector<int> steps;
  for (int i = 0; i < k; i++) {
    int a;
    cin >> a;
    ;
    int b;
    cin >> b;
    ;
    ;
    for (int j = a; j <= b; j++) steps.push_back(j);
  }
  vector<int> ladder(n + 1, 0);
  sort(steps.begin(), steps.end());
  int ans = slv(n, steps, ladder);
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
