#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 998244353;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  ll L, R;
  vector<int> S;
  for (int i = 0; i < (k); i++) {
    cin >> L >> R;
    for (int j = (L); j < (R + 1); j++) {
      S.push_back(j);
    }
  }
  int m = S.size();
  sort(S.begin(), S.end());
  vector<ll> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = (1); i < (n); i++) {
    for (auto d : S) {
      if (i + d <= n) {
        dp[i + d] = (dp[i + d] + dp[i]) % MOD;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
