#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
int main(void) {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  vector<ll> load(n, 0);
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
      mp[i]++;
    }
  }
  load[0] = 1;
  for (int i = 0; i < n - 1; i++) {
    if (load[i] == 0) continue;
    for (auto d : mp) {
      if (i + d.first >= n) continue;
      if (load[i + d.first] == 0) {
        load[i + d.first] = load[i];
      } else {
        load[i + d.first] += load[i];
      }
      load[i + d.first] %= 998244353;
    }
  }
  cout << load[n - 1] << endl;
  return 0;
}
