#include <bits/stdc++.h>
using namespace std;
long MOD = 998244353;
int main() {
  long n, m;
  cin >> n >> m;
  vector<long> seen(n + 1, 0);
  for (long i = 1; i < m + 1; i++) {
    long x, y;
    cin >> x >> y;
    for (long j = x; j < y + 1; j++) {
      if (seen[j] == 0) {
        seen[j] += 1;
      }
    }
  }
  vector<long> can(0);
  for (long i = 1; i < n + 1; i++) {
    if (seen[i]) {
      can.push_back(i);
    }
  }
  vector<long> v(n + 10, 0);
  v[1] = 1;
  for (long i = 1; i < n; i++) {
    for (long j = 0; j < long(can.size()); j++) {
      if (i + can[j] > n + 1) continue;
      v[i + can[j]] += v[i] % MOD;
      v[i + can[j]] %= MOD;
    }
  }
  cout << v[n] % MOD;
}
