#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 1e5 + 10;
int a[N];
int f[N];
struct node {
  int s[2];
} T[N];
bool cmp(node t1, node t2) { return t1.s[0] < t2.s[0]; }
int main() {
  f[1] = 1;
  f[2] = -1;
  a[1] = 1;
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) cin >> T[i].s[0] >> T[i].s[1];
  sort(T + 1, T + k + 1, cmp);
  for (int i = 1; i <= n; ++i) {
    if (i > 2)
      f[i] = (f[i - 1] + a[i]) % mod;
    else if (i == 2)
      f[i] = a[i];
    for (int j = 1; j <= k; ++j) {
      if (i + T[j].s[0] <= n) (a[i + T[j].s[0]] += f[i]) %= mod;
      if (i + T[j].s[1] + 1 <= n)
        (((a[i + T[j].s[1] + 1] -= f[i]) %= mod) += mod) %= mod;
    }
  }
  cout << f[n] << endl;
}
