#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long dp[N];
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> keep(k);
  for (int i = 0; i < k; i++) {
    cin >> keep[i].first >> keep[i].second;
  }
  sort(keep.begin(), keep.end());
  long long prefix = 0;
  dp[1] = 1;
  for (auto y : keep) {
    dp[1 + y.first] += dp[1];
    dp[1 + y.first] %= 998244353;
    if (1 + y.second + 1 < N) {
      dp[1 + y.second + 1] -= dp[1];
      if (dp[1 + y.second + 1] < 0) {
        dp[1 + y.second + 1] += 998244353;
      }
    }
  }
  for (long long i = 2; i < n + 1; i++) {
    long long z = (prefix + dp[i] + 998244353) % 998244353;
    dp[i] += prefix;
    dp[i] = (dp[i] + 998244353) % 998244353;
    prefix = z;
    for (auto y : keep) {
      dp[i + y.first] += dp[i];
      dp[i + y.first] = (dp[i + y.first] + 998244353) % 998244353;
      if (i + y.second + 1 < N) {
        dp[i + y.second + 1] -= dp[i];
        if (dp[i + y.second + 1] < 0) {
          dp[i + y.second + 1] += 998244353;
        }
      }
    }
  }
  cout << dp[n];
}
int main() {
  int ntc = 1;
  while (ntc--) {
    solve();
  }
}
