#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int n, k;
  cin >> n >> k;
  long long int x, y;
  set<long long int> s;
  for (long long int i = 0; i < k; i++) {
    cin >> x >> y;
    s.insert(x);
    s.insert(y);
  }
  long long int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  x = *s.begin();
  dp[x] = 1;
  for (long long int i = x; i <= n; i++) {
    for (auto x : s) {
      if (i + x <= n) {
        dp[i + x] = (dp[i + x] + dp[i]) % 998244353;
        dp[i + x] %= 998244353;
      }
    }
  }
  cout << dp[n] % 998244353 << "\n";
  return 0;
}
