#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 998244353;
constexpr ll INF = 1LL << 60;
int main() {
  long N, K;
  cin >> N >> K;
  vector<pair<long, long> > S(K);
  for (int i = (int)(0); i < (int)(K); i++) {
    long l, r;
    cin >> l >> r;
    S[i] = {l, r};
  }
  vector<long> C(K, 0);
  sort(S.begin(), S.begin());
  vector<long> DP(N + 1, 0);
  DP[1] = 1;
  for (int i = (int)(2); i < (int)(N + 1); i++) {
    for (int j = (int)(0); j < (int)(K); j++) {
      if (i - S[j].first <= 0)
        continue;
      else if (i - S[j].second <= 0) {
        C[j] += DP[i - S[j].first];
        DP[i] += C[j];
      } else {
        C[j] = C[j] + DP[i - S[j].first] - DP[i - S[j].second - 1];
        DP[i] += C[j];
      }
      C[j] %= mod;
      DP[i] %= mod;
    }
  }
  cout << DP[N] << endl;
}
