#include <bits/stdc++.h>
using namespace std;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dx9[9] = {0, 1, 0, -1, 1, -1, 1, 0, -1};
int dy9[9] = {0, 1, 1, 1, 0, 0, -1, -1, -1};
const int INF = 1e9;
const long long LLINF = 1e18;
const int MAX_V = 1e6 + 1;
int n, k;
const int mod = 998244353;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint dp[20005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  vector<pair<long long, long long> > vp;
  for (int i = 0; i < (int)(k); i++) {
    long long l, r;
    cin >> l >> r;
    vp.push_back(pair<int, int>(l, r));
  }
  dp[0] = 1;
  dp[1] = -1;
  mint sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    sum += dp[i];
    dp[i] = sum;
    for (int j = 0; j < (int)(k); j++) {
      long long l = vp[j].first, r = vp[j].second;
      if (i + l <= n) dp[i + l] += dp[i];
      if (i + r + 1 <= n) dp[i + r + 1] -= dp[i];
    }
  }
  cout << dp[n - 1] << endl;
}
