#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=998244353;

int main()
{
  ll n,k;
  cin>>n>>k;
  vector<pair<ll,ll>> sections;
  for (int i = 0; i < k; ++i)
  {
    ll l,r;
    cin>>l>>r;
    sections.push_back({l,r});
  }
  vector<ll> f(2*n+100,0),a(2*n+100,0);
  f[1]=1;
  for (int i = 1; i < n; ++i)
  {
    for (int j = 0; j < k; ++j)
    {
      ll l=sections[j].first;
      ll r=sections[j].second;
      a[i+l]+=f[i];
      a[i+r+1]+=(mod-f[i]);
      a[i+l]%=mod;
      a[i+r+1]%=mod;
    }
    if (i==1) f[i+1]=a[i+1];
    else f[i+1]=f[i]+a[i+1];
    f[i+1]%=mod;
  }
  cout<<f[n]<<endl;
}