#include <bits/stdc++.h>
using namespace std;
int a[200010];
int lk[20];
int rk[20];
int main() {
  int n;
  int m;
  int k;
  int ans, lkk, rkk;
  m = 998244353;
  a[1] = 1;
  cin >> n >> k;
  for (int i = 0; i < (int)(k); i++) cin >> lk[i] >> rk[i];
  for (int i = (2); i <= (int)(n); i++) {
    a[i] = a[i - 1];
    for (int j = 0; j < (int)(k); j++) {
      rkk = max(i - rk[j] - 1, 0);
      lkk = max(i - lk[j], 0);
      a[i] += a[lkk] - a[rkk] + m;
      a[i] %= m;
    }
  }
  ans = a[n] - a[n - 1] + m;
  ans %= m;
  cout << ans << endl;
  return 0;
}
