#include <bits/stdc++.h>
using namespace std;
const long long BASE = (long long)(998244353);
long long dp[200001];
long long cumsum[200001];
int main() {
  int n, k;
  int left[11], right[11];
  cin >> n >> k;
  for (int i = 0; i < (k); i++) {
    cin >> left[i] >> right[i];
  }
  dp[1] = 1;
  cumsum[1] = 1;
  for (int i = (2); i < (n + 1); i++) {
    long long ret = 0;
    for (int j = 0; j < (k); j++) {
      int l = max(1, i - right[j]);
      int r = i - left[j];
      if (l > r) break;
      long long tmp = (cumsum[r] - cumsum[l - 1]) % BASE;
      ret = (ret + tmp) % BASE;
      if (ret < 0) ret += BASE;
    }
    dp[i] = ret;
    cumsum[i] = (cumsum[i - 1] + dp[i]) % BASE;
  }
  cout << dp[n] << endl;
  return 0;
}
