#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=200001;
int p=998244353;
typedef long long ll;
typedef pair<int,int> P;
int main()
{
  int n,k,i,j;
  P l[10];
  ll res;
  ll r[N_MAX];
  cin >> n >> k;
  for(i=0;i<k;i++)
    cin >> l[i].first >> l[i].second;
  r[0]=0;
  r[1]=1;
  for(i=2;i<=n;i++){
    r[i]=r[i-1];
    for(j=0;j<k;j++){
      if(i-l[j].first>=0)
        r[i]+=r[i-l[j].first];
      if(i-l[j].second>0)
        r[i]-=r[i-l[j].second-1];
    }
    r[i]%=p;
  }
  res=(r[n]-r[n-1])%p;
  if(res<0)
    res+=p;
  cout << res << endl;
  return 0;
}