#include <bits/stdc++.h>
using namespace std;
long long f[200005], l[25], p[25], qzh[200005];
signed main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    cin >> l[i] >> p[i];
  }
  f[1] = qzh[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j = 1; j <= k; j++) {
      if (i - l[j] > 0) {
        f[i] += (qzh[i - l[j]] - qzh[max(i - p[j] - 1, 0ll)]) % 998244353;
        f[i] %= 998244353;
      }
    }
    qzh[i] = qzh[i - 1] + f[i];
    qzh[i] %= 998244353;
  }
  cout << f[n];
  return 0;
}
