#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n,k,l[N],r[N];
const LL mod=998244353;
LL dp[N],s[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>k;
  for(int i=1;i<=k;i++)cin>>l[i]>>r[i];dp[1]=1;s[1]=1;
  for(int i=2;i<=n;i++){
    for(int j=1;j<=k;j++){
      int L=max(1,l[j]);
      int R=min(i-1,r[j]);
      if(L>R)continue;
      (dp[i]+=(0ll+s[i-(L)]-s[i-R-1]+mod)%mod)%=mod;
    }
    (s[i]=s[i-1]+dp[i])%=mod;
  }
  cout<<dp[n]<<endl;
  return 0;
}