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