#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
vector<long long> arr;
long long dp[200001];
long long solve(long long pos, long long target) {
  if (pos == target) return 1;
  if (target < pos) return 0;
  if (dp[pos] != -1) return dp[pos] % mod;
  long long ans = 0;
  for (long long i = 0; i < arr.size(); i++) {
    ans = (ans % mod + solve(pos + arr[i], target) % mod) % mod;
  }
  return dp[pos] = ans % mod;
}
int main() {
  long long n, k;
  cin >> n >> k;
  set<long long> S;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    S.insert(l);
    S.insert(r);
  }
  for (long long x : S) arr.push_back(x);
  for (long long i = 0; i <= n; i++) {
    dp[i] = -1;
  }
  cout << solve(1, n) << endl;
}
