#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=998244353;
const long double PI=3.14159265358979;
const ll MAX=0;

ll DP[600020];

int main() {
 
  ll N,K;
  cin>>N>>K;
  ll L[K];
  ll R[K];
  rep(i,K){
    cin>>L[i]>>R[i];
  }
  DP[0]=1;DP[1]=-1;
  rep(i,N){
    rep(j,K){
      DP[i+L[j]]+=DP[i];
      DP[i+L[j]]%=MOD;
      DP[i+R[j]+1]-=DP[i];
      DP[i+R[j]+1]%=MOD;
    }
    DP[i+1]+=DP[i];
    DP[i+1]%=MOD;
  }
  while(DP[N-1]<0){
    DP[N-1]+=MOD;
  }
  cout<<DP[N-1];
    
}

