#include <bits/stdc++.h>
using namespace std;
const long long int maxx = 3 * 1e5, limit = 9 * 1e18, MOD = 998244353;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, k;
  cin >> n >> k;
  map<long long int, long long int> mark;
  for (long long int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    for (long long int i = a; i <= b; i++) {
      mark[i] = 1;
    }
  }
  long long int l, r;
  bool flag = false;
  vector<pair<long long int, long long int> > range;
  for (long long int i = 1; i <= 1e6; i++) {
    if (mark[i] == 1) {
      if (!flag) {
        l = i;
        flag = true;
      }
    } else {
      if (flag) {
        r = i - 1;
        flag = false;
        range.push_back(make_pair(l, r));
      }
    }
  }
  long long int dp[n + 2];
  memset(dp, 0, sizeof(dp));
  ;
  dp[1] = 1;
  dp[0] = 0;
  long long int pre[n + 2];
  memset(pre, 0, sizeof(pre));
  ;
  pre[0] = 0;
  pre[1] = 1;
  for (long long int i = 2; i <= n; i++) {
    for (long long int j = 0; j < range.size(); j++) {
      long long int l = range[j].first;
      long long int r = range[j].second;
      if (l >= i) continue;
      l = i - l;
      r = i - r;
      if (l < 1) l = 1;
      if (r < 1) r = 1;
      if (l >= i) l = i - 1;
      if (r >= i) r = i - 1;
      long long int minl = min(l, r);
      long long int maxr = max(l, r);
      dp[i] = (dp[i] + (pre[maxr] - pre[minl - 1]) % MOD) % MOD;
    }
    pre[i] = (pre[i - 1] + dp[i]) % MOD;
  }
  cout << dp[n] << '\n';
  ;
}
