#include <bits/stdc++.h>
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long int MOD = 998244353;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector<ll> s;
  for (long long i = 0; i < (k); ++i) {
    ll l, r;
    cin >> l >> r;
    for (; l <= r; l++) s.push_back(l);
  }
  vector<ll> dp(n + 5, 0);
  dp[1] = 1;
  for (ll i = 1; i <= n; i++) {
    for (long long j = 0; j < (s.size()); ++j) {
      if (i + s[j] <= n) {
        dp[i + s[j]] += dp[i];
        dp[i + s[j]] %= MOD;
      }
    }
  }
  cout << dp[n] % MOD << "\n";
  return 0;
}
