#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
struct nod {
  int l, r;
} a[300005];
int su[30005], dp[30005], n, k;
int sum(int l, int r) { return ((su[r] - su[l - 1]) % mod + mod) % mod; }
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> a[i].l >> a[i].r;
  }
  dp[1] = su[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i >= a[j].l) {
        dp[i] = (sum(max(0, i - a[j].r), i - a[i].l)) % mod;
      }
      su[i] = (su[i - 1] + dp[i]) % mod;
    }
  }
  cout << dp[n];
  return 0;
}
