#include <bits/stdc++.h>
using namespace std;
int dx[8] = {0, 0, 1, 1, -1, -1, 1, -1};
int dy[8] = {1, -1, 1, -1, 1, -1, 0, 0};
int n, m, a[200005], dp[200005];
vector<int> v;
int fn(int pos) {
  if (pos == 1) return 1;
  int &z = dp[pos];
  if (z != -1) return z;
  z = 0;
  for (int i = 0; i < m; i++) {
    if (pos - v[i] >= 0) {
      z += fn(pos - v[i]);
      z %= 998244353;
    } else
      break;
  }
  return z;
}
int main() {
  scanf("%d", &n);
  int k;
  scanf("%d", &k);
  int l, r;
  for (int i = 0; i < k; i++) {
    scanf("%d", &l);
    scanf("%d", &r);
    for (int j = l; j <= r; j++) v.push_back(j);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  m = v.size();
  memset(dp, -1, sizeof(dp));
  int ans = fn(n);
  cout << ans << endl;
}
