#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5, M = 15, MOD = 998244353;
long long a[N];
long long f[N];
long long x[M], y[M];
long long n, m;
long long qzh[N];
inline long long modbez(long long a, long long b) {
  register long long res = a % b;
  if (res < 0)
    return res + b;
  else
    return res;
}
void DP() {
  f[n] = 1;
  for (long long i = n; i >= 1; i--) {
    for (long long j = 1; j <= m; j++) {
      f[i] = modbez(f[i] + qzh[i + x[j]] - qzh[i + y[j] + 1], MOD);
    }
    qzh[i] = modbez(qzh[i + 1] + f[i], MOD);
  }
  cout << f[1] % MOD << endl;
}
void common_DP() {
  f[n] = 1;
  for (long long i = n; i >= 1; i--)
    for (long long j = 1; j <= m; j++)
      for (long long k = x[j]; k <= y[j]; k++) {
        if (i + k <= n) {
          f[i] = (f[i] + f[i + k]) % MOD;
        }
      }
  cout << f[1] << endl;
}
signed main() {
  memset(f, 0, sizeof(f));
  memset(a, 0, sizeof(a));
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
  }
  if (n > 1e4)
    common_DP();
  else
    DP();
}
