#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int main()
{
   int n,k,count=0,minx=9999999;
   cin>>n>>k;
   register ans[200005]={0};
   ans[1]=1;
   register yn[200005]={0};
   for(int i=1;i<=k;i++)
   {
      int a,b;
      cin>>a>>b;
      for(int i=a;i<=b;i++)
      {
         count++;
         yn[count]=i;
      }
      minx=min(a,minx);
   }   
   for(register int i(1);i<=n-minx;++i)
   {
      if(ans[i]>0)
      {
         for(int j=1;j<=count;j++)
         {
            int kk=i+yn[j];
            if(kk<=n)
            {
            ans[kk]+=ans[i];
            ans[kk]%=998244353;
            }
         }
      }
      /*
      for(int i=1;i<=n;i++)
      {
         cout<<ans[i]<<" ";
      }
      cout<<endl;
      */
   }
   cout<<ans[n]<<endl;
   return 0;
}
