#include <bits/stdc++.h>
using namespace std;
int a[400010];
int b[200010];
int main() {
  int n;
  int m;
  int k;
  int p, lk, rk;
  m = 998244353;
  p = 0;
  a[1] = 1;
  cin >> n >> k;
  for (int i = 0; i < (int)(k); i++) {
    cin >> lk >> rk;
    for (int i = (lk); i <= (int)(rk); i++) {
      b[p] = i;
      p++;
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] == 0) continue;
    for (int j = 0; j < (int)(p); j++) {
      a[i + b[j]] += a[i];
      a[i + b[j]] %= m;
    }
  }
  cout << a[n] << endl;
  return 0;
}
