#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
using namespace std;
inline long long in() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const long long mod = 998244353;
const long long N = 4e5 + 8;
long long pre[N], a[N];
long long l[11], r[11];
int32_t main() {
  long long n = in();
  long long k = in();
  for (long long i = 1; i <= k; i++) l[i] = in(), r[i] = in();
  a[1] = 1;
  for (long long i = 1; i <= n; i++) {
    if (a[i] == 0 and i != 1) continue;
    for (long long j = 1; j <= k; j++) {
      pre[i + l[j]] += a[i];
      pre[i + r[j] + 1] -= a[i];
    }
    for (long long i = 1; i <= n; i++) {
      pre[i] += pre[i - 1];
      pre[i] %= mod;
    }
    for (long long i = 1; i <= n; i++) {
      a[i] += pre[i];
      a[i] %= mod;
      pre[i] = 0;
    }
  }
  cout << a[n] % mod;
}
