#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> S;
  vector<long long> r(3 * n, 0);
  for (int i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    for (long long i = a; i <= b; i++) {
      S.push_back(i);
    }
  }
  sort(S.begin(), S.end());
  r[1] = 1;
  for (long long i = 1; i < n; i++) {
    if (r[i] == 0)
      continue;
    else {
      for (auto p : S) {
        if (i + p <= n) {
          r[i + p] += r[i];
          r[i + p] %= mod;
        }
      }
    }
  }
  cout << r[n] << endl;
}
