#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const long long N = 211000;
long long dp[N];
long long a[N];
long long b[N];
long long s[N];
const long long mod = 998244353;
void update(long long l, long long r, long long val) {
  b[l] += val;
  b[r + 1] -= val;
}
void FinalArray(long long n) {
  for (long long i = 0; i < n; i++) {
    s[i] = s[i - 1] + b[i];
    a[i] += s[i];
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    long long r, l;
    cin >> l >> r;
    update(l, r, 1);
  }
  FinalArray(N);
  dp[0] = 1;
  vector<long long> v;
  for (long long i = 0; i < N; i++) {
    if (s[i]) v.push_back(i);
  }
  for (long long i = 1; i < n; i++) {
    dp[i] = 0;
    for (long long j = 0; j < (long long)v.size(); j++) {
      if (i >= v[j]) {
        dp[i] += dp[i - v[j]];
        dp[i] = dp[i] % mod;
      }
    }
  }
  cout << dp[n - 1];
}
