#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long INF = 1e18;
const double EPS = 1e-8;
template <typename T, typename U>
bool chmax(T& max, const U& x) {
  if (max < x) {
    max = x;
    return true;
  }
  return false;
}
template <typename T, typename U>
bool chmin(T& min, const U& x) {
  if (min > x) {
    min = x;
    return true;
  }
  return false;
}
int main() {
  long long n, k;
  cin >> n >> k;
  set<long long> ivl;
  vector<long long> dp(n + 1, 0);
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      ivl.insert(j);
    }
  }
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (auto j : ivl) {
      if (i - j > 0) {
        dp[i] += dp[i - j];
        dp[i] %= MOD;
      }
    }
  }
  cout << dp[n] << endl;
}
