#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N, K, mod = 998244353, ans = 0;
  cin >> N >> K;
  vector<long long int> L, R, DP(N + 1), pSum(N + 1);
  for (int i = 0; i < (int)(K); i++) {
    long long int l, r;
    cin >> l >> r;
    L.push_back(l);
    R.push_back(r);
  }
  DP[1] = 1;
  pSum[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int k = 0; k < (int)(K); k++) {
      if (i >= R[k]) {
        DP[i] -= pSum[i - R[k]];
      }
      if (i >= L[k]) {
        DP[i] += pSum[i - L[k]];
      }
    }
    DP[i] = DP[i] % mod;
    pSum[i] = (pSum[i - 1] + DP[i]) % mod;
  }
  cout << DP[N];
  return 0;
}
