#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
int main() {
  ll N, K, L, R;
  cin >> N >> K;
  vector<int> S;
  while (cin >> L >> R) {
    for (int s = L; s <= R; ++s) {
      S.push_back(s);
    }
  }
  sort(begin(S), end(S));
  vector<ll> dp(N + 1);
  dp[1] = 1;
  for (int i = 1; i != N; ++i) {
    if (!dp[i]) continue;
    for (int s : S) {
      if (i + s > N) break;
      dp[i + s] = (dp[i + s] + dp[i]) % MOD;
    }
  }
  cout << dp[N] << endl;
}
