#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long INF = 1e18;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long fastexp(long long x, long long n) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result *= x;
    x *= x;
    n = n / 2;
  }
  return result;
}
long long modularExp(long long x, long long n, long long mod) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % mod;
    x = ((x % mod) * (x % mod)) % mod;
    n = n / 2;
  }
  return (result) % mod;
}
bool isPrime(long long n) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
bool mycomp(pair<long long, long long> &a, pair<long long, long long> &b) {
  if (a.first != b.first)
    return a.first < b.first;
  else
    return a.second < b.second;
}
vector<long long> par(2005), sz(2005, 1);
long long froot(long long x) {
  if (x == par[x]) return x;
  return par[x] = froot(par[x]);
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > v(k);
  vector<long long> dp(n + 1);
  long long i, j;
  for (i = 0; i < k; i++) cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end());
  vector<long long> st;
  for (i = 0; i < k; i++) {
    for (j = v[i].first; j <= v[i].second; j++) st.push_back(j);
  }
  long long sz = st.size();
  dp[1] = 1;
  for (i = 1; i <= n; i++) {
    long long mdiff = (n - i);
    long long idx = upper_bound(st.begin(), st.end(), mdiff) - st.begin();
    idx--;
    for (j = 0; j <= min(sz - 1, idx); j++)
      dp[i + st[j]] = (dp[i + st[j]] % mod + dp[i] % mod) % mod;
  }
  cout << dp[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
}
