#include <bits/stdc++.h>
using namespace std;
vector<long long int> BIT;
const long long int mod = 998244353;
void update(long long int pos, long long int val) {
  for (long long int i = pos; i <= BIT.size() - 1; i += (i & (-i))) {
    BIT[i] = (BIT[i] % mod + val % mod) % mod;
  }
}
long long int getSum(long long int pos) {
  long long int ret = 0;
  for (long long int i = pos; i > 0; i -= (i & (-i))) {
    ret = (ret % mod + BIT[i] % mod) % mod;
  }
  return ret;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int> > ranges;
  for (long long int i = 0; i < k; ++i) {
    long long int l, r;
    cin >> l >> r;
    ranges.push_back(make_pair(l, r));
  }
  BIT = vector<long long int>(n + 1);
  update(1, 1);
  update(2, -1);
  for (long long int i = 1; i <= n - 1; i++) {
    if (getSum(i)) {
      long long int val = getSum(i);
      for (long long int j = 0; j < (long long int)ranges.size(); ++j) {
        long long int l = ranges[j].first, r = ranges[j].second;
        update(i + l, val);
        update(i + r + 1, -1 * val);
      }
    }
  }
  long long int ans = getSum(n);
  cout << ans << '\n';
}
signed main() {
  long long int test_cases;
  test_cases = 1;
  while (test_cases-- > 0) solve();
}
