#include <bits/stdc++.h>
struct edge {
  long long to;
  long long cost;
};
using namespace std;
using vi = vector<long long>;
using vii = vector<vector<long long>>;
using vb = vector<bool>;
using qi = queue<long long>;
using P = pair<long long, long long>;
using graph = vector<vector<edge>>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long inf = 1LL << 60;
const long long mod = 1000000007;
const long long maxn = 2e5 + 2;
long long n, m, k;
vi dp(maxn);
vi num;
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) num.push_back(j);
  }
  long long len = (long long)num.size();
  dp[0] = 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < len; j++) {
      if (num[j] <= i) {
        dp[i] += dp[i - num[j]];
        dp[i] %= 998244353;
      }
    }
  }
  cout << std::fixed << std::setprecision(10) << dp[n - 1] << "\n";
}
