#include <bits/stdc++.h>
using namespace std;
template <class T>
void read_v(T& x, std::istream& in) {
  in >> (x);
}
template <class A>
void read_vec(vector<A>& x, std::istream& in) {
  for (auto& a : x) read_v(a, in);
}
long long iceildiv(const long long a, const long long b) {
  if (a == 0) {
    return 0;
  }
  return (1 + ((a - 1) / b));
}
bool sortpairbysec(const pair<long long, long long>& a,
                   const pair<long long, long long>& b) {
  return (a.second < b.second);
}
template <typename T>
T factmod(T a, T modulus) {
  long long res = 1, i;
  for (i = 2; i <= a; i++) {
    res *= i;
    res %= modulus;
  }
  return res;
}
template <typename T>
long long powmod(T a, T b, const long long m) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans *= a;
      ans %= m;
    }
    a *= a;
    a %= m;
    b >>= 1;
  }
  return ans;
}
template <typename T>
long long power(T a, T b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans *= a;
    }
    a *= a;
    b >>= 1;
  }
  return ans;
}
const long long CMOD = 998244353;
long long dp_solve(const long long n,
                   const vector<pair<long long, long long>>& sv) {
  long long k = (long long)(sv).size();
  vector<long long> dp(n + 1, 0);
  for (auto x : sv) {
    dp[x.first] = 1;
    dp[x.second] = -1;
  }
  for (long long i = 1; i <= n; i++) {
    if (i > 1) {
      dp[i] += dp[i - 1];
      dp[i] %= CMOD;
    }
    for (long long j = 0; j < k; j++) {
      long long l, r;
      tie(l, r) = sv[j];
      if (i + l <= n) {
        dp[i + l] += dp[i];
        dp[i + l] %= CMOD;
      }
      if (i + r <= n) {
        dp[i + r] -= dp[i];
        dp[i + r] %= CMOD;
        dp[i + r] = (dp[i + r] < 0 ? dp[i + r] + CMOD : dp[i + r]);
      }
    }
  }
  long long ans = dp[n - 1] % CMOD;
  ans = (ans < 0 ? ans + CMOD : ans);
  return ans;
}
void ssolve(std::istream& in, std::ostream& out) {
  long long n, k;
  in >> n >> k;
  vector<pair<long long, long long>> sv;
  for (long long i = 0; i < (k); i++) {
    long long l, r;
    in >> l >> r;
    r++;
    sv.emplace_back(make_pair(l, r));
  }
  sort(begin(sv), end(sv));
  long long ans = dp_solve(n, sv);
  out << (ans) << endl;
  return;
}
class DLeapingTak {
 public:
  void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);
    long long t;
    long long READ = 0;
    if (READ)
      in >> t;
    else
      t = 1;
    while (t--) {
      ssolve(in, out);
    }
  }
};
long long main() {
  DLeapingTak solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
}
