#include <bits/stdc++.h>
using namespace std;
int N, K;
int MOD = 998244353;
int L[10], R[10];
int memo[200001];
int f(int);
int f_(int x) {
  if (x < 1) return 0;
  if (x == 1) return 1;
  int ans = 0;
  for (int k = 0; k < K; ++k) {
    for (int i = L[k]; i <= R[k]; ++i) {
      ans += f(x - i);
      ans %= MOD;
    }
  }
  return ans;
}
int f(int x) {
  if (x < 1) return 0;
  if (memo[x] == -1) memo[x] = f_(x);
  return memo[x];
}
int main() {
  cin >> N >> K;
  for (int k = 0; k < K; ++k) {
    cin >> L[k] >> R[k];
  }
  for (int i = 0; i < sizeof(memo) / sizeof(memo[0]); ++i) {
    memo[i] = -1;
  }
  cout << f(N) << endl;
}
