#include <bits/stdc++.h>
using namespace std;
const long long int md = 1e9 + 7;
const long long int M1 = 998244353;
long long int mod(long long int n) { return ((n % M1) + M1) % M1; }
long long int power(long long int x, long long int y) {
  long long int res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = res * x;
    x = x * x;
    y = y >> 1;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int>> v(k);
  for (long long int i = 0; i < k; i++) cin >> v[i].first >> v[i].second;
  long long int dp[n + 2];
  for (long long int i = 1; i < n + 1; i++) dp[i] = 0;
  dp[0] = 0, dp[1] = 1;
  for (long long int i = 2; i < n + 1; i++) {
    long long int cur = 0;
    for (long long int j = 0; j < k; j++) {
      if (v[j].first >= i) continue;
      long long int l = max(1LL, i - v[j].second);
      long long int r = i - v[j].first;
      cur += dp[r] - dp[l - 1];
    }
    cur = mod(cur);
    dp[i] = mod(dp[i - 1] + cur);
  }
  cout << dp[n] - dp[n - 1] << '\n';
}
