#include <bits/stdc++.h>
using namespace std;
const long long maxint = 2e18;
const long long minint = -2e18;
const int mod = 998244353;
int n;
const int M = 2e5 + 5;
vector<pair<int, int>> edges;
int main() {
  int k;
  scanf("%d%d", &n, &k);
  edges.assign(k, pair<int, int>());
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &edges[i].first, &edges[i].second);
  }
  sort(edges.begin(), edges.end());
  vector<long long> dp(n + 1, 0), sum(n + 1, 0);
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto e : edges) {
      if (i - e.first < 1) continue;
      dp[i] += (sum[i - e.first] - sum[max(0, i - e.second - 1)]) % mod;
      dp[i] %= mod;
    }
    sum[i] = (sum[i - 1] % mod + dp[i] % mod) % mod;
    sum[i] %= mod;
  }
  cout << dp[n] % mod << '\n';
  return 0;
}
