#include <bits/stdc++.h>
const int MAX = 1e6 + 9;
const long long mod = 998244353;
const int TOT_PRIMES = 19;
const int MAX_A = 70;
using namespace std;
vector<int> adj[MAX];
int prime[MAX];
int main() {
  int n, k;
  cin >> n >> k;
  long long dp[n + 10000];
  memset(dp, 0, sizeof(dp));
  dp[0] = 0;
  dp[1] = 1;
  vector<pair<int, int> > v;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
  }
  for (int i = 1; i <= n + 5; i++) {
    if (i > 2) dp[i] += dp[i - 1];
    long long now = dp[i] % mod;
    for (int j = 0; j < v.size(); j++) {
      dp[i + v[j].first] = (dp[i + v[j].first] + now);
      dp[i + v[j].second + 1] = (dp[i + v[j].second + 1] - now);
    }
  }
  cout << dp[n] % mod;
}
