#include <bits/stdc++.h>
using namespace std;
int64_t TN = 1;
void solve() {
  int64_t n, ans = 0, a, b, k;
  cin >> n >> k;
  vector<int64_t> v;
  set<int64_t> st;
  for (int i = 0; i < k; ++i) {
    cin >> a >> b;
    st.insert(a);
    st.insert(b);
  }
  for (auto it : st) v.push_back(it);
  vector<int64_t> cur(n + 1);
  cur[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto it : st) {
      if (i - it > 0) {
        cur[i] += cur[i - it];
      }
    }
  }
  cout << cur[n] % 998244353;
}
int main() {
  for (int i = 0; i < TN; ++i) {
    solve();
  }
  return 0;
}
