#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll solve(ll N, ll num, vector<ll> v, ll idx, vector<ll> n) {
  ll mod = 998244353;
  ll count = 0;
  if (N < num) return count;
  if (N % num == 0) {
    n.at(idx - 1) = N / num;
    vector<ll> row;
    for (int i = 0, i_len = (int)(n.size()); i < i_len; ++i) {
      for (int j = 0, j_len = (int)(n.at(i)); j < j_len; ++j) {
        row.push_back(v.at(i));
      }
    }
    do {
      count++;
      count %= mod;
    } while (next_permutation((row).begin(), (row).end()));
  }
  if (idx >= (ll)v.size()) return count;
  for (int i = (0), i_len = (int)(N / num); i < i_len; ++i) {
    n.at(idx - 1) = i;
    count += solve(N - i * num, v.at(idx), v, idx + 1, n);
    count %= mod;
  }
  return count;
}
int main() {
  ll N;
  cin >> N;
  ll K;
  cin >> K;
  vector<ll> v;
  vector<int> ok(N, 0);
  for (int i = 0, i_len = (int)(K); i < i_len; ++i) {
    ll L1;
    cin >> L1;
    ll L2;
    cin >> L2;
    v.push_back(L1);
    if (L1 != L2) v.push_back(L2);
  }
  vector<ll> n(v.size(), 0);
  ll count = solve(N - 1, v.at(0), v, 1, n);
  cout << count << endl;
  return 0;
}
