#include <bits/stdc++.h>
using namespace std;
long long a[2000005], dp[2000005];
int main() {
  ;
  long long n, k;
  cin >> n >> k;
  set<long long> st;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j = x; j <= y; j++) a[j] = 1;
  }
  vector<long long> v;
  dp[1] = 1;
  for (long long i = 1; i <= n; i++) {
    if (a[i]) v.push_back(i);
  }
  sort(v.begin(), v.end());
  long long sz = v.size();
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < sz; j++) {
      if (i >= v[j]) {
        dp[i] = (dp[i] + dp[i - v[j]]) % 998244353;
      } else
        break;
    }
  }
  cout << dp[n] << endl;
}
