#include <bits/stdc++.h>
using namespace std;
using pp = pair<int, int>;
using ll = long long;
int main() {
  ll N, K, mod = 998244353;
  cin >> N >> K;
  vector<ll> dp(N + 1, 0);
  dp[1] = 1;
  vector<ll> L(0);
  ll l1, l2;
  for (ll i = 0; i < K; i++) {
    cin >> l1 >> l2;
    for (ll j = l1; j <= l2; j++) {
      L.push_back(j);
    }
  }
  sort(L.begin(), L.end());
  for (ll i = 1; i <= N; i++) {
    for (ll j = 0; j < L.size(); j++) {
      if (L[j] >= i) {
        break;
      }
      dp[i] += dp[i - L[j]];
      dp[i] -= dp[i] / mod * mod;
    }
  }
  cout << dp[N] << endl;
}
