#include <bits/stdc++.h>
const long long int mod = 998244353, def = -1;
long long int n, k, l, r, numS = 0, S[200010] = {0}, ans[200010] = {0},
                          DP[200010] = {def};
long long int dp(long long int a) {
  long long int p = a;
  if (p < 1) return 0;
  if (p == 1) return 1;
  long long int rtn = 0;
  for (int i = 0; i < numS; i++) {
    long long int N = p - S[i];
    long long int plus;
    if (DP[N] != def)
      plus = DP[N];
    else {
      plus = dp(N);
      DP[N] = plus;
    }
    rtn += plus;
    rtn = rtn % mod;
  }
  return rtn;
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%lld%lld", &l, &r);
    for (int j = l; j <= r; j++) {
      S[numS] = j;
      numS++;
    }
  }
  for (int i = 1; i <= n; i++) DP[i] = def;
  long long int ans = dp(n);
  printf("%lld", ans);
  return 0;
}
