#include <bits/stdc++.h>
using namespace std;
void Main() {
  int64_t mod = 998244353;
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> S(2 * K);
  for (int64_t i = 0; i < K; i++) {
    cin >> S[2 * i] >> S[2 * i + 1];
  }
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  int64_t ans[N + 1];
  ans[1] = 1;
  ans[0] = 0;
  for (int64_t n = 2; n <= N; n++) {
    ans[n] = 0;
    for (int64_t i = 0; i < S.size(); i++) {
      if (n - S[i] >= 1) {
        ans[n] += ans[n - S[i]];
        ans[n] %= mod;
      }
    }
  }
  cout << ans[N] << endl;
}
int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
