#include <bits/stdc++.h>
using namespace std;
vector<int> v;
const int N = 2e5 + 5, mod = 998244353;
long long dp[N];
bool vis[N];
int n;
long long solve(long long x) {
  if (x == n) {
    return 1;
  }
  if (x > n) {
    return 0;
  }
  if (vis[x]) {
    return dp[x];
  }
  for (auto it : v) {
    dp[x] = (dp[x] + solve(x + it)) % mod;
  }
  vis[x] = 1;
  return dp[x];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int k;
  cin >> n >> k;
  int a[n + 2];
  memset(a, 0, sizeof(a));
  memset(dp, 0, sizeof(dp));
  memset(vis, 0, sizeof(vis));
  while (k--) {
    int l, r;
    cin >> l >> r;
    a[l]++, a[r + 1]--;
  }
  for (int i = 1; i <= n; i++) {
    a[i] += a[i - 1];
    if (a[i] > 0) {
      v.push_back(i);
    }
  }
  cout << solve(1) << '\n';
  return 0;
}
