#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;

const int mod=998244353;
const int inf=-1;
const int sz=2e5;

#define pi acos(-1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gap ' '
#define lb lower_bound
#define ub upper_bound
#define SIN(x) sin(x * pi / 180.0)
#define COS(x) cos(x * pi / 180.0)
#define clr(x) memset(x,0,sizeof(x))
#define all(x) sort(x.begin(),x.end())
#define rall(x) reverse(x.begin(),x.end())
#define dbg puts("finding wrong")
#define case(x,y) printf("Case %lld: %lld\n",++x,y)
#define fastio ios::sync_with_stdio(false);cin.tie(0)


ll coin[sz],way[sz];
map<ll,ll>use;

bool cmp(ll a , ll b)
{
    return a<b;
}

int main()
{
  fastio;
  ll n, x, y, i , j, r;
  cin>>n>>r;
  ll k=0;
  for(i=1; i<=r; i++)
  {
      cin>>x>>y;
      for(j=x; j<=y; j++)
      {
              coin[k]=j;
              k++;
      }
  }
  memset(way,0,sizeof(way));
  n--;
  sort(coin,coin,cmp);
  way[0]=1;
  for(i=1; i<=n; i++)
  {
      for(j=0; j<k; j++)
      {
          if(i>=coin[j])
          way[i]=(way[i]+way[i-coin[j]])%mod;
      }
  }
  cout<<way[n]<<endl;
}
