#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
bool is_integer(double x) { return floor(x) == ceil(x); }
int main() {
  int n;
  cin >> n;
  long long int a[200000] = {-1};
  int k;
  cin >> k;
  int s[200000];
  int l, r;
  int cnt;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s[cnt++] = j;
    }
  }
  a[n - 1] = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == 0) {
      for (int j = 0; s[j] != 0; j++) {
        if (i - s[j] < 0) {
          continue;
        }
        a[i - s[j]] = 0;
      }
    }
  }
  a[0] = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] != 0) {
      continue;
    }
    for (int j = 0; s[j] != 0; j++) {
      if (i - s[j] < 0) {
        continue;
      }
      a[i] = (a[i] + a[i - s[j]]) % 998244353;
    }
  }
  cout << a[n - 1] << endl;
}
