#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  vector<pair<int, int> > range(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
    range[i] = pair<int, int>(l[i], r[i]);
  }
  sort(range.begin(), range.end());
  vector<int> map(n + 1);
  map[1] = 1;
  bool lastcheck = false;
  if (range[0].first == 1) {
    range[0].first = 2;
    lastcheck = true;
  }
  for (int now = 1; now < n; now++) {
    if (map[now] == 0) {
      continue;
    }
    for (int i = 0; i < k; i++) {
      bool check = false;
      for (int j = range[i].first; j <= range[i].second; j++) {
        if (now + j <= n) {
          map[now + j] += map[now];
          map[now + j] %= mod;
        } else {
          check = true;
          break;
        }
      }
      if (check) {
        break;
      }
    }
    if (now + range[0].first > n) {
      break;
    }
  }
  if (lastcheck) {
    for (int now = 1; now < n; now++) {
      map[now + 1] += map[now];
      map[now + 1] %= mod;
    }
  }
  cout << map[n] << endl;
  return 0;
}
