#include <bits/stdc++.h>
using namespace std;
long long N = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> l(n), r(n);
  vector<long long> possible;
  for (int i = 0; i < k; i++) {
    cin >> l.at(i) >> r.at(i);
    for (long long j = l.at(i); j <= r.at(i); j++) {
      possible.push_back(j);
    }
  }
  vector<long long> dp(n, 0);
  dp.at(0) = 1;
  for (long long i = 1; i < n; i++) {
    for (auto j : possible) {
      if (0 <= i - j && i - j < n) {
        dp.at(i) += dp.at(i - j);
        dp.at(i) %= N;
      }
    }
  }
  cout << dp.at(n - 1) << endl;
}
