#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 998244353;
vector<pair<long long, long long> > prime_factorize(long long N) {
  vector<pair<long long, long long> > res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    long long ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}
bool dp[30][200010];
int main() {
  int a, b, n, k, s, t, m, v;
  cin >> n >> k;
  m = n - 1;
  vector<int> p;
  for (int i = 0; i < (k); ++i) {
    cin >> s;
    p.push_back(s);
    cin >> t;
    p.push_back(t);
  }
  sort(p.begin(), p.end());
  p.erase(unique(p.begin(), p.end()), p.end());
  v = p.size();
  for (int i = 0; i < (v); ++i) {
    a = p.at(i);
    for (int j = 0; j < (n % a); ++j) {
      p.push_back(a);
    }
  }
  v = p.size();
  memset(dp, 0, sizeof(dp));
  dp[0][0] = true;
  int q[200009];
  for (int o = 0; o < (v); ++o) {
    q[o] = p.at(o);
  }
  for (int i = 0; i < (v); ++i) {
    for (int j = 0; j < (m); ++j) {
      (dp[i + 1][j] += dp[i][j]) %= MOD;
      if (j >= q[i]) (dp[i + 1][j] += dp[i][j - q[i]]) %= MOD;
    }
  }
  cout << dp[v][m] << endl;
  return 0;
}
