#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f ? -x : x;
}
const int N = 2e6 + 100, p = 998244353;
long long n, m, t[N], A[12], B[12];
long long ask(long long x) {
  long long tot = 0;
  for (long long i = x; i; i -= i & -i) tot = (tot + t[i]) % p;
  return tot;
}
void add(long long x, long long d) {
  for (long long i = x; i <= n; i += i & -i) t[i] = (t[i] + d) % p;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    A[i] = read(), B[i] = read();
    if (A[i] > B[i]) swap(A[i], B[i]);
  }
  t[1] = 1;
  for (int i = 1; i <= n; i++) {
    long long a = ask(i);
    if (!a) continue;
    for (int j = 1; j <= m; j++) {
      add(i + A[j], a);
      add(i + B[j] + 1, -a);
    }
  }
  cout << ask(n) << endl;
  return 0;
}
