#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=998244353;

int main(){
  int n,k;
  cin>>n>>k;
  int l[k],r[k];
  rep(i,0,k) cin>>l[i]>>r[i];
  ll a[n];
  rep(i,0,n) a[i]=0;
  a[0]=1;
  ll sum[n+1];
  sum[0]=0;
  sum[1]=1;
  rep(i,1,n){
    rep(j,0,k){
      if(i-l[j]+1>=0) a[i]+=sum[i-l[j]+1];
      if(i-r[j]>=0) a[i]-=sum[i-r[j]];
      if(a[i]<0) a[i]+=mod;
      if(a[i]>mod) a[i]-=mod;
    }
    sum[i+1]=sum[i]+a[i];
    if(sum[i+1]>mod) sum[i+1]-=mod;
  }
  cout<<a[n-1]<<endl;
}