#include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <vector>  
#include <string>
#include <cmath>
#include <ctime>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <ext/pb_ds/assoc_container.hpp>    // PBDS
#include <ext/pb_ds/tree_policy.hpp>      // PBDS

using namespace std;
using namespace __gnu_pbds;                 // PBDS

/* typedef starts */

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> PBDS_INT;               // PBDS for int
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> PBDS_LL;    // PBDS for long long

/* typedef ends */

/* macro starts */

#define PI acos(-1)
#define EPS 1e-9
#define INF 998244353
#define fastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define sinD(degree) sin((degree * PI) / 180.0)
#define cosD(degree) cos((degree * PI) / 180.0)
#define tanD(degree) tan((degree * PI) / 180.0)
#define cotD(degree) (1.0 / tanD(degree))
#define secD(degree) (1.0 / cosD(degree))
#define cosecD(degree) (1.0 / sinD(degree))
#define asinD(value) (asin(value) * 180.0) / PI
#define acosD(value) (acos(value) * 180.0) / PI
#define atanD(value) (atan(value) * 180.0) / PI
#define forn(i,n) for(int i=0;i<n;i++)
#define value_at_index(x) find_by_order(x)
#define index_of(x) order_of_key(x)
#define pb push_back
#define setval(add,n) memset(add,n,sizeof(add))
#define max(a,b) a>b ? a : b
#define forr(i,a,b) for(int i=a;i<b;i++)

/* macro ends */

/* function starts */

/// calculates n-th (0-based) Gray Code
template<typename dataType>
dataType nthGrayCode(dataType n)
{
    return (n ^ (n >> 1));
}

/// generates all possible subsets for the given set
//template<typename dataType>
// void generateAllSubset(vector<dataType> &data)
// {
//     int i, j, n;
//     n = data.size();

//     for (i = 0; i < (1 << n); i++) {
//         for (j = 0; j < n; j++) {
//             if (i & (1 << j)) {
//                 cout << data[j] << " ";
//             }
//         }
//         cout << "\n";
//     }
// }


void swap(ll *a, ll *b){
	ll *temp=a;
	*a=*b;
	*b=*temp;
}


int n,k;
int dp[200005];
set<int> s;

int func(int i){
 if(i<=0)return 0;
 if(i==1)return 1;
 if(dp[i]!=0)return dp[i];

 int ans=0;
 for(auto x:s){
    ans=((ans%INF)+(func(i-x)%INF))%INF;
 }
 return dp[i]=ans;
}


void solve(){
  cin >> n;
  cin >> k;
  setval(dp,0);
  int l[n],r[n];
  
  forn(i,k){
    cin >> l[i] >> r[i];
    s.insert(l[i]);
    s.insert(r[i]);
  }
  dp[1]=1;
  int ans=func(n);
  cout << ans << '\n';
}





int main()
{
  #ifndef ONLINE_JUDGE
       freopen("in.txt", "r", stdin);
       freopen("out.txt", "w", stdout);
  #endif
  fastIO;
    int t=1;
    //cin >> t;
    while(t--){
     solve();
     
    }
    return 0;
    }