#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
int digit(long long x) {
  if (x / 10 == 0) return 1;
  return digit(x / 10) + 1;
}
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool is_prime(long long N) {
  if (N == 1) return false;
  for (long long i = 2; i * i <= N; i++) {
    if (N % i == 0) return false;
  }
  return true;
}
long long lcm(long long a, long long b) {
  return ((a * b == 0)) ? 0 : (a / gcd(a, b) * b);
}
double DegreeToRadian(double degree) { return degree * M_PI / 180.0; }
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> p(k);
  for (int i = 0; i < k; i++) {
    cin >> p[i].first >> p[i].second;
  }
  vector<int> dp(n + 1);
  vector<int> sum(n + 1);
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto v : p) {
      int left = max(0, i - v.second);
      int right = max(0, i - v.first);
      if (right < 0) continue;
      dp[i] += sum[right] - sum[left - 1];
      dp[i] %= MOD;
    }
    sum[i] = sum[i - 1] + dp[i];
    sum[i] %= MOD;
  }
  dp[n] = (dp[n] + MOD) % MOD;
  cout << dp[n] << endl;
  return 0;
}
