#include <bits/stdc++.h>
const long long MOD = 998244353;
using namespace std;
long long dfs(long long N, vector<long long> table, vector<long long> &dp) {
  long long ans = 0;
  if (N == 1) {
    return 1;
  }
  if (N <= 0) {
    return 0;
  }
  if (dp[N] != -1) {
    return dp[N];
  }
  for (int i = 0; i < table.size(); i++) {
    ans = (ans % MOD + dfs(N - table[i], table, dp) % MOD) % MOD;
  }
  dp[N] = ans;
  return dp[N];
}
int main() {
  long long N, K;
  cin >> N >> K;
  set<long long> dict;
  vector<long long> table;
  vector<long long> dp(N + 1, -1);
  long long L, R;
  for (int i = 0; i < K; i++) {
    cin >> L >> R;
    dict.insert(L);
    dict.insert(R);
  }
  for (auto x : dict) {
    table.push_back(x);
  }
  cout << dfs(N, table, dp) << endl;
}
