#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long mod = 998244353;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0', ch = getchar();
  }
  return x * f;
}
int n, m, l[N], r[N];
long long f[N], g[15];
void solve() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    l[i] = read();
    r[i] = read();
  }
  long long ans = 0;
  f[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i - l[j] >= 1) g[j] += f[i - l[j]];
      if (i - r[j] > 1) g[j] -= f[i - r[j] - 1];
      g[j] = (g[j] + mod) % mod;
      f[i] = (f[i] + g[j]) % mod;
    }
  }
  cout << f[n] << endl;
}
int main() {
  int T = 1;
  while (T--) solve();
}
