#include <bits/stdc++.h>
const int M = 998244353;
using namespace std;
const int mxn = 2e5;
int n, m, p[mxn];
vector<int> adj[mxn], ans;
int dp[mxn];
int vis[mxn], act[mxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  int a, b;
  cin >> n >> k;
  set<int> s;
  int dp[n + 1];
  int x = INT_MAX;
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < k; i++) {
    cin >> a >> b;
    s.insert(a);
    s.insert(b);
    x = min(x, min(a, b));
  }
  dp[x] = 1;
  for (int i = 1; i <= n; i++) {
    for (auto x : s) {
      if (i >= x) dp[i] = (dp[i] + dp[i - x]) % M;
    }
  }
  cout << dp[n] << endl;
}
