#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2>
inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const long long mod = 998244353;
template <class T>
inline void fix(T &x) {
  if (x >= mod | x <= -mod) {
    x %= mod;
  }
  if (x < 0) {
    x += mod;
  }
}
const long long MAX_N = 1e6 + 10;
long long pref[MAX_N];
long long sum(long long l, long long r) {
  if (r <= 0) {
    return 0;
  } else if (l <= 0) {
    return pref[r];
  }
  return (pref[r] - pref[l - 1] + mod) % mod;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  vector<pair<long long, long long> > arr;
  cin >> n >> k;
  arr.resize(k);
  for (long long i = 0; i < k; i++) {
    cin >> arr[i].first >> arr[i].second;
  }
  pref[0] = 0;
  pref[1] = 1;
  for (long long i = 2; i <= n; i++) {
    long long curr = 0;
    for (long long j = 0; j < k; j++) {
      curr = (curr + sum(i - arr[j].second, i - arr[j].first)) % mod;
    }
    pref[i] = (pref[i - 1] + curr) % mod;
  }
  cout << (pref[n] - pref[n - 1]) % mod;
  return 0;
}
