#include <bits/stdc++.h>
using namespace std;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % 998244353 + 998244353) % 998244353) {}
  mint operator-() { return mint(-x); }
  mint operator+=(mint rhs) {
    x += rhs.x;
    if (x >= 998244353) x -= 998244353;
    return *this;
  }
  mint operator-=(mint rhs) {
    x -= rhs.x;
    if (x < 0) x += 998244353;
    return *this;
  }
  mint operator*=(mint rhs) {
    x = x * rhs.x % 998244353;
    return *this;
  }
  mint operator+(mint rhs) { return mint(*this) += rhs; }
  mint operator-(mint rhs) { return mint(*this) -= rhs; }
  mint operator*(mint rhs) { return mint(*this) *= rhs; }
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<mint> dp(n + 10, 0);
  vector<mint> sum(n + 10, 0);
  dp[0] = 1;
  mint p = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      sum[i + l[j]] += dp[i];
      sum[i + r[j] + 1] -= dp[i];
    }
    p += sum[i + 1];
    dp[i + 1] = p;
  }
  cout << dp[n - 1].x << endl;
  return 0;
}
