#include <bits/stdc++.h>
using namespace std;
signed main() {
  unsigned long long n, m;
  cin >> n >> m;
  unsigned long long l[m + 1], r[m + 1];
  for (unsigned long long i = 1; i <= m; ++i) cin >> l[i] >> r[i];
  unsigned long long f[n + 1];
  f[1] = 1;
  f[0] = 0;
  for (unsigned long long i = 2; i <= n; ++i) {
    f[i] = f[i - 1];
    for (unsigned long long j = 1; j <= m; ++j) {
      if (l[j] > i) continue;
      unsigned long long L, R;
      L = i - l[j];
      R = i - r[j];
      if (R <= 0) R = 1;
      f[i] = (f[i] + f[L] + 998244353 - f[R - 1]) % 998244353;
    }
  }
  cout << (f[n] + 998244353 - f[n - 1]) % 998244353 << endl;
  return 0;
}
