#include<iostream>
#include<bits/stdc++.h>
#define mod 998244353
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define precision(x) cout << setprecision(x) << fixed;
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout << a[i]; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;



int32_t main()
{
   fast;
   #ifndef ONLINE_JUDGE
   freopen("goodluckin.txt","r",stdin);
   freopen("goodluckout.txt","w",stdout);
   #endif

   int n,k;
   cin >> n >> k;
   pair<int,int> a[k];
   for(int i = 0 ; i < k ; i++){
    cin >> a[i].first >> a[i].second;
   }

   vector<int>possible;
   sort(a,a+k);
   stack<pair<int,int>> s; 
  
   
    s.push(a[0]); 
  
    for (int i = 1 ; i < k; i++) 
    { 
        // get interval from stack top 
        auto top = s.top(); 
  
        // if current interval is not overlapping with stack top, 
        // push it to the stack 
        if (top.second < a[i].first) 
            s.push(a[i]); 
  
        else if (top.second < a[i].second) 
        { 
            top.second = a[i].second; 
            s.pop(); 
            s.push(top); 
        } 
    } 

    while(s.empty() == false){
      int x1 = s.top().first;
      int x2 = s.top().second;
      for(int i = x1 ; i<=x2 ; i++){
        possible.push_back(i);
      }
      s.pop();
    }

    int dp[n+1] = {0};

    dp[0] = 0;
    dp[1] = 1;
    sort(all(possible));
    for(int i = 2 ; i<=n ; i++){
      int c = 0;
      for(int j : possible){
          if((i-j)<=0){
            break;
          }
         c = (c+dp[i-j])%mod;
      }
      dp[i] = c%mod;
    }

    cout << dp[n];

}
