#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int n, k, ans;
map<int, int> v, o, v3;
struct nod {
  int l, r;
} a[15];
void dfs(int x) {
  if (x == n) {
    ans++;
    return;
  }
  if (x > n) return;
  o = v;
  v = v3;
  for (int i = 1; i <= k; i++) {
    if (x + a[i].l <= n && v[a[i].l] == 0) dfs(x + a[i].l), v[a[i].l] = 1;
    if (x + a[i].r <= n && v[a[i].r] == 0) dfs(x + a[i].r), v[a[i].r] = 1;
  }
  v = o;
  return;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> a[i].l >> a[i].r;
  }
  dfs(1);
  cout << ans % mod;
  return 0;
}
