#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
template <class T, class C>
void chmax(T& a, C b) {
  a > b ?: a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
  a < b ?: a = b;
}
int main() {
  long long N, K;
  cin >> N >> K;
  const long long mod = 998244353;
  vector<long long> S;
  for (long long i = 0; i < K; i++) {
    long long left, right;
    cin >> left >> right;
    for (long long j = left; j <= right; j++) {
      S.push_back(j);
    }
  }
  sort(S.begin(), S.end());
  vector<long long> a(N + 1, 0);
  a[1] = 1;
  for (long long i = 1; i < N; i++) {
    if (a[i] == 0) continue;
    for (long long x : S) {
      if (i + x > N) {
        break;
      }
      a[i + x] += a[i];
      a[i + x] %= mod;
    }
  }
  cout << a[N] << endl;
}
