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