#include<iostream>
using namespace std;

pair<int, int> R[100];
long dp[200010];
int DIV = 998244353;

int main() {
  int N, K; cin >> N >> K;
  for (int i = 0; i < K; i++) {
    int l, r; cin >> l >> r; R[i] = make_pair(l, r);
  }
  for (int i = 0; i <= N; i++) dp[i] = 0;
  dp[1] = 1;
  for (int i = 1; i < N; i++) {
    dp[i+1] = dp[i];
    for (int k = 0; k < K; k++) {
      dp[i+1] += dp[max(0, i-R[k].first+1)] - dp[max(0, i-R[k].second)] + DIV;
      dp[i+1] %= DIV;
    }
  }
  cout<<(dp[N]-dp[N-1]+DIV)%DIV << endl;
}