#include <bits/stdc++.h>
int dp[200000 + 5];
int size;
int s[10 + 5];
int compare_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int dfs(int a) {
  if (a == 0) return 1;
  if (a < 0) return 0;
  if (dp[a] >= 0) return dp[a];
  int ans = 0;
  for (int i = 0; i < size; i++) {
    ans += dfs(a - s[i]);
    ans %= 998244353;
  }
  return dp[a] = ans;
}
int main(void) {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) scanf("%d %d", &s[i * 2], &s[i * 2 + 1]);
  size = k * 2;
  qsort(s, size, sizeof(int), compare_int);
  for (int i = 1; i < size; i++) {
    if (s[i - 1] == s[i]) {
      for (int j = i; j < size - 1; j++) {
        s[j] = s[j + 1];
      }
      size--;
    }
  }
  for (int i = 0; i < n; i++) dp[i] = -1;
  printf("%d\n", dfs(n - 1));
  return 0;
}
