#include <bits/stdc++.h>
using namespace std;
struct BIT {
  vector<long long> bit;
  long long n;
  BIT(long long n) {
    this->n = n + 1;
    bit.assign(n + 1, 0);
  }
  long long sum(long long idx) {
    long long ret = 0;
    if (idx <= 0) {
      return 0;
    }
    for (++idx; idx > 0; idx -= idx & -idx) ret += bit[idx], ret %= 998244353;
    return ret;
  }
  long long sum(long long l, long long r) {
    long long x = sum(r);
    long long y = sum(l - 1);
    long long ans = (x - y + 998244353) % 998244353;
    return ans;
  }
  void add(long long idx, long long delta) {
    for (++idx; idx < n; idx += idx & -idx) bit[idx] += delta;
    bit[idx] %= 998244353;
  }
};
signed main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, k;
  cin >> n >> k;
  BIT b(n);
  vector<long long> dp(n + 1);
  vector<pair<long long, long long> > segs(k);
  for (long long i = 0; i < k; i++) {
    cin >> segs[i].first >> segs[i].second;
  }
  sort((segs).begin(), (segs).end());
  b.add(1, 1);
  for (long long i = 2; i <= n; i++) {
    for (long long j = 0; j < k; j++) {
      long long l = segs[j].first, r = segs[j].second;
      long long needl = max(0LL, i - r), needr = max(0LL, i - l);
      dp[i] += b.sum(needl, needr);
      dp[i] %= 998244353;
    }
    b.add(i, dp[i]);
  }
  cout << dp[n];
}
