#include <bits/stdc++.h>
using namespace std;
long long suf[300005];
long long dp[300005];
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > v;
  v.resize(k);
  for (long long i = 0; i < k; i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());
  dp[n] = 1;
  suf[n] = 1;
  for (long long i = n - 1; i >= 1; i--) {
    long long now = 0;
    for (long long j = 0; j < k; j++) {
      long long l = min(n, i + v[j].first), r = min(n, i + v[j].second);
      now += suf[l] - suf[r + 1];
      now %= 998244353;
      now = (now + 998244353) % 998244353;
    }
    dp[i] = now;
    suf[i] = suf[i + 1] + dp[i];
    suf[i] %= 998244353;
  }
  cout << dp[1];
}
