#include<bits/stdc++.h>
using namespace std;

#define fl(n)             for(long long int i=0;i<n;i++)
#define sz(a)             int((a).size())
#define tr(c,i)           for(auto i = (c).begin(); i != (c).end(); i++)
#define trr(c,i)          for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define present(c,x)      ((c).find(x) != (c).end())
#define cpresent(c,x)     (find(all(c),x) != (c).end())
#define vi                vector <int>
#define vvi               vector < vi >
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define ll                long long
#define fr                first
#define sc                second
#define vc                vector
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define M                 998244353


int solve()
{
  int n,k;
  cin>>n>>k;
  set<int> st;
  for(int i=0;i<k;i++)
  {
    int t1,t2;
    cin>>t1>>t2;
    for(int j=t1;j<=t2;j++)
    {
      st.insert(j);
    }
  }

  int a[n+1]={0};
  a[n]=1;
  for(int i=n;i>1;i--)
  {
    for(auto val:st)
    {
      if(i-val<1)
        break;
      a[i-val]+=a[i];
      a[i-val]%=M;
    }
  }
  cout<<a[1];
  


  return 0;
}


int main() {
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

      ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);       

  int t=1;
  //cin>>t;
  while(t--)
  { 
    solve();
  }
  return 0;
}


