#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long n, k, l[15], r[15];
struct BinaryIndexedTree {
  long long a[200005];
  void clear() { memset(a, 0, sizeof a); }
  long long lowbit(long long x) { return x & (-x); }
  void modify(long long x, long long val) {
    for (long long i = x; i <= n; i += lowbit(i)) a[i] += val, a[i] %= MOD;
  }
  long long query(long long x) {
    long long ans = 0;
    for (long long i = x; i; i -= lowbit(i)) ans += a[i], ans %= MOD;
    return ans;
  }
} bit;
int main() {
  memset(bit.a, 0, sizeof bit.a);
  scanf("%lld %lld", &n, &k);
  bit.modify(1, 1);
  bit.modify(2, -1);
  for (long long i = 1; i <= k; ++i) scanf("%lld %lld", &l[i], &r[i]);
  for (long long i = 1; i <= n; ++i) {
    long long val = bit.query(i);
    for (long long j = 1; j <= k; ++j) {
      long long L = i + l[j], R = i + r[j];
      if (L > n) continue;
      R = min(R, n);
      bit.modify(L, val);
      bit.modify(R + 1, -val);
    }
  }
  long long ans = bit.query(n);
  printf("%lld", (ans % MOD + MOD) % MOD);
  return 0;
}
