#include <bits/stdc++.h>
using namespace std;

const int mod = 998244353;
const int _ = 2e5 + 10;
int N, K, L[11], R[11], f[_], sum[_];

int main() {
#ifndef ONLINE_JUDGE
  freopen("d.in", "r", stdin);
  freopen("d.out", "w", stdout);
#endif
  cin >> N >> K;
  for (int i = 1; i <= K; ++i) cin >> L[i] >> R[i];
  sum[1] = f[1] = 1;
  for (int i = 2; i <= N; ++i) {
    for (int j = 1; j <= K; ++j) {
      if (i - L[j] < 1) continue;
      f[i] = (f[i] + (sum[i - L[j]] - sum[max(1, i - R[j]) - 1] + mod) % mod) %
             mod;
    }
    sum[i] = (sum[i - 1] + f[i]) % mod;
  }
  cout << f[N] << endl;
  return 0;
}