#include <bits/stdc++.h>
using namespace std;
int main() {
  const long long M = 9988244353;
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v(k);
  for (int i = 0; i < k; ++i) {
    int x, y;
    cin >> x >> y;
    v[i] = make_pair(x, y);
  }
  set<int> s;
  for (auto i : v) {
    s.insert(i.first);
    s.insert(i.second);
  }
  vector<long long> dp(n + 1);
  dp[0] = 1;
  for (int i = 1; i < n + 1; ++i) {
    long long k = 0;
    for (auto x : s)
      if ((i - x) >= 0) k = (k % M + dp[i - x] % M) % M;
    dp[i] = k;
  }
  cout << dp[n - 1] << '\n';
  return 0;
}
