#include<bits/stdc++.h>
#define pb push_back 
 #define fo(i,n) for(int i=0;i<n;i++)
#define ll long long 
#define int long long 
#define Mod 10000000000007 
#define maxn 200005
#define MAX 4294967296  // 2^32
const int M=1e9+7;
#define ip pair<int,int>
#define test(t) ll t;cin>>t;while(t--)
  
using namespace std;

long long gcd(int x,int y){
    if(y>x)swap(x,y);
    if(y==0)return x;
    return gcd(y,x%y);
}


void solve(){
vector<pair<int,int>>v;
int n,k;
cin>>n>>k;
int t=n;
for(int i=0;i<k;i++){
    int a,b;
    cin>>a>>b;
    b++;
    v.push_back({a,b});
}
int dp[n+1]={0};
dp[0]=1;
dp[1]=-1;
for(int i=0;i<n;i++){
    if(i>0)dp[i]+=dp[i-1];
        for(int j=0;j<k;j++){
            if(i+v[j].first<n)dp[i+v[j].first]+=dp[i];
            if(i+v[j].second<n)dp[i+v[j].second]-=dp[i];
        }


}

cout<<dp[n-1]%998244353;


}

signed main(){


    // std::string binary = std::bitset<8>(n).to_string();
    ios::sync_with_stdio(0);
    cin.tie(0);
   
solve();


  


}