#include <bits/stdc++.h>
using namespace std;
const int N = 300010, mod = 998244353;
int l[N], r[N], f[N];
int c[N];
inline long long lowbit(long long x) { return x & (-x); }
long long sum(long long x) {
  long long res = 0;
  while (x) {
    res += c[x];
    res %= mod;
    x -= lowbit(x);
  }
  return res;
}
void add(long long x, long long y) {
  while (x < N) {
    c[x] += y;
    c[x] %= mod;
    x += lowbit(x);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; ++i) {
    cin >> l[i] >> r[i];
  }
  f[1] = 1;
  for (long long i = 1; i <= n; ++i) {
    if (i != 1) f[i] = sum(i);
    for (long long j = 1; j <= k; ++j) {
      add(i + l[j], f[i]);
      add(i + r[j] + 1, -f[i]);
    }
  }
  cout << f[n] << endl;
  ;
  return 0;
}
