#include <bits/stdc++.h>
using namespace std;
long long dp[200005];
int main() {
  long long N, K;
  cin >> N >> K;
  vector<pair<long long, long long> > LR(K);
  for (long long i = 0; i < (K); ++i) {
    cin >> LR[i].first >> LR[i].second;
  }
  long long cur = 1;
  dp[0] = -1;
  long long ans = -1;
  for (long long i = 0; i < (N); ++i) {
    for (long long j = 0; j < (K); ++j) {
      long long l = LR[j].first;
      long long r = LR[j].second;
      dp[i + l - 1] += cur;
      dp[i + l - 1] %= 998244353;
      dp[i + r] -= cur;
      dp[i + r] += 998244353;
      dp[i + r] %= 998244353;
    }
    if (i == N - 1) {
      ans = cur;
    }
    cur += dp[i];
    cur %= 998244353;
  }
  cout << ans << endl;
}
