#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define vt vector
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;
template<typename T> T power(T a,T b){T r=1;while(b){if(b&1)r*=a;b/=2;a*=a;}return r;}


int main()
{
  fastio;
  int n,k;
  cin>>n>>k;
  vt<int> l(n),r(n);
  vt<int> s;
  range(i,0,k)
  {
    cin>>l[i]>>r[i];
    range(j,l[i],r[i]+1)
      s.pb(j);
  }

  vt<ll> dp(n+1,0);
  for(auto i:s)
  {
    dp[i]++;
  }

  for(int i=1;i<=n;i++)
  {
    for(auto j:s)
    {
      if(i-j<0)break;
      dp[i]=dp[i]+dp[i-j];
      dp[i]%=mod;
    }
  }

  cout<<dp[n-1];

}