#include <bits/stdc++.h>
using namespace std;
using ip = pair<int, int>;
const int N = 2e5 + 1, K = 10, mod = 998244353;
int n, k, dp[N];
ip d[K];
int solve(int x) {
  if (dp[x] != -1) return dp[x];
  dp[x] = 0;
  for (int i = 0; i < k; ++i)
    for (int u = x - d[i].first, v = x - d[i].second; u >= v and u > 0; --u)
      dp[x] += solve(u), dp[x] %= mod;
  return dp[x];
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cin >> n >> k,
      memset(dp, -1, sizeof dp), dp[1] = 1;
  for (int i = 0; i < k; ++i) cin >> d[i].first >> d[i].second;
  sort(d, d + k), cout << solve(n);
}
