#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
long long power(long long x, long long y) {
  if (x == 1 || y == 0) return 1;
  long long res = 1;
  x = x % 998244353;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % 998244353;
    y = y >> 1;
    x = (x * x) % 998244353;
  }
  return res;
}
long long dp[200005];
long long solve(long long st, long long n, pair<long long, long long> p[],
                long long k) {
  if (st == n) return 1;
  if (dp[st] != -1) return dp[st];
  long long so = 0;
  for (long long i = (0); i < (k); ++i) {
    for (long long j = p[i].first; j <= p[i].second; j++) {
      if (j + st > n) break;
      so = (so + solve(st + j, n, p, k)) % 998244353;
    }
  }
  return dp[st] = so;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n, k;
  cin >> n >> k;
  pair<long long, long long> p[k];
  for (long long i = (0); i < (n + 1); ++i) dp[i] = -1;
  for (long long i = (0); i < (k); ++i) {
    cin >> p[i].first >> p[i].second;
  }
  cout << solve(1, n, p, k);
  return 0;
}
