#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <iostream>
#include <ctype.h>
#include <string>
typedef long long ll;
using namespace std;




int main(){

  ll mod=998244353;

  ll n,k,a,b,c;
  vector<int> vec(0);
  


  cin>>n>>k;
  
  vector<int> sum(n+1,0);
  vector<pair<int,int>> pair;

  rep(i,k){
      cin>>a>>b;
      pair.push_back(make_pair(a,b));
  }

  sort(pair.begin(), pair.end());
  

  sum[1]=1;
  rep(i, n+1){
      if(i==0||i==1)continue;
    
	  sum[i]=sum[i-1];
      rep(j,k){
          c=0;
          if(pair[j].first > i) break;
          if(pair[j].second > i){
              sum[i] += sum[i-pair[j].first];
              sum[i] %=mod;
          }else{
            sum[i] +=  sum[i-(pair[j].first)]-sum[i-(pair[j].second + 1)];
            sum[i] %= mod;
          }
      }
  }
  c = sum[n]-sum[n-1];
  
  while(c < 0) c+=mod; 
  cout<<c;