#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;

int nCrevenoroddfinder(int n,int r)
{
    int a=r;
    int b=n-r;
    for(int i=0;i<30;i++)
    {
        int x=1<<i;
        if((x&a)&&(x&b))
        {
            return 0;//even
        }
    }
    return 1;//odd
}

ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}
ll nax=1e6+2;
int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  ll n,k;
  cin>>n>>k;
  set<ll> s;
  pair<ll,ll> p[k+1];
  for(int i=0;i<k;i++){
        int l,r;cin>>l>>r;
        p[i].ff=l,p[i].ss=r;
  }
  ll mini=*(s.begin());
  ll maxi=*(--s.end());
  
  int dp[n + 1]={},pp[k+2]={}; 
    int temp = 0; 
    dp[0] = 1; 
    for (int i = 1; i < n; i++) 
    { 
         // dp[i]+=dp[i-1];
        for(int j=0;j<k;j++){
              ll x=0;
              mini=p[j].ff,maxi=p[j].ss;
              //cout<<mini<<" "<<maxi<<endl;
              if(i-mini<0) continue;
              
              if(i-mini>=0) pp[j]+=(dp[i-mini]);//x+=dp[i-1]%998244353;
              //if(i-1>=0) 
              if(i-1-maxi>=0) pp[j]-=(dp[i-1-maxi]);
              pp[j]+=998244353;
                  pp[j]%=998244353;
              dp[i]+=pp[j];
              dp[i]%=998244353;
        }
      //  cout<<dp[i]<<" ";
    } 
    cout<<dp[n-1];
}



  
