#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int L[10];
int R[10];
bool Map[200007];
int K;
bool in(int x) {
  for (int i = 0; i < K; i++) {
    if (L[i] <= x && x <= R[i]) return true;
  }
  return false;
}
int path(int from, int to) {
  int ans = 0;
  if (from > to) return 0;
  if (from == to) return 1;
  for (int i = 0; i < K; i++) {
    for (int j = L[i]; j <= R[i]; j++) {
      ans += path(from + j, to);
      ans %= 998244353;
    }
  }
  return ans;
}
int ans[200007];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  ans[1] = 1;
  cin >> N >> K;
  int count = 0;
  for (int i = 0; i < (K); i++) {
    int l, r;
    cin >> l >> r;
    L[i] = l;
    R[i] = r;
    for (int j = l; j <= r; j++) {
      Map[j] = true;
    }
  }
  for (int i = 1; i <= (N); i++) {
    for (int p = 0; p < (K); p++) {
      for (int j = L[p]; j <= R[p]; j++) {
        if (j <= i) ans[i] += ans[i - j], ans[i] %= 998244353;
      }
    }
  }
  cout << ans[N] << endl;
  return 0;
}
