#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 998244353;
int main() {
  long long N, K;
  cin >> N >> K;
  set<long long> s;
  for (long long i = 0; i < K; i++) {
    long long a, b;
    cin >> a >> b;
    for (long long j = a; j <= b; j++) {
      s.insert(j);
    }
  }
  vector<long long> a(N + 1);
  a[1] = 1;
  for (long long i = 2; i <= N + 1; i++) {
    for (auto p : s) {
      if (p < i) {
        a[i] += a[i - p];
        a[i] %= MOD;
      }
    }
  }
  cout << a[N] % MOD << endl;
}
