#include <bits/stdc++.h>
using namespace std;
int n, k;
long long dp[200005];
vector<long long> s;
const long long mod = 998244353;
long long solve(int idx) {
  if (idx == n - 1) return 1;
  long long &ret = dp[idx];
  if (~ret) return ret;
  ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (idx + s[i] >= n) continue;
    ret = (ret + solve(idx + s[i]) % mod) % mod;
  }
  return ret % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    long long a, b;
    cin >> a >> b;
    if (a == b)
      s.push_back(a);
    else
      s.push_back(a), s.push_back(b);
  }
  memset(dp, -1, sizeof dp);
  cout << solve(0);
}
