#include<bits/stdc++.h>
using namespace std;

int MOD(int a, int b){
  int x = a % b;
  if(x >= 0)
    return (x);
  else
    return (x + b);
}

int main(){
  int N, K;
  int mod = 998244353;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  for(int i = 0; i < K; i++)
    cin >> L[i] >> R[i];
  vector<int> dp(N+1);
  vector<int> s(N+1);
  dp[1] = 1;
  s[1] = 1;
  for(int i = 2; i <= N; i++){
  	for(int j = 0; j < K; j++){
      int l = max(i - R[j], 1);
      int r = i - L[j];
      if(r < 1)	continue;
      dp[i] = MOD(dp[i] + s[r] - s[l-1], mod);
    }
    s[i] = MOD(s[i-1] + dp[i], mod);
  }
  cout << dp[N] << endl;
  return 0;
}