#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353LL;
const long long INF = (1LL << 60LL);
long long dp[200010];
int main() {
  long long N, K;
  scanf("%lld %lld", &N, &K);
  vector<pair<long long, long long>> list;
  for (long long i = 0; i < K; i++) {
    long long a, b;
    scanf("%lld %lld", &a, &b);
    list.emplace_back(make_pair(a, b));
  }
  long long plus = 1;
  for (long long i = 1; i < N; i++) {
    plus += dp[i];
    plus = (plus + MOD) % MOD;
    for (long long j = 0; j < list.size(); j++) {
      long long from = list[j].first;
      long long to = list[j].second;
      if (i + from < N + 5) {
        dp[i + from] += plus;
        dp[i + from] %= MOD;
      }
      if (i + to + 1 < N + 5) {
        dp[i + to + 1] -= plus;
        dp[i + to + 1] %= MOD;
      }
    }
  }
  cout << (dp[N]) << endl;
}
