#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}

const ll MOD = 1e9+7;
long long Comb(int n, int i){long long ans = 1; if(i>n || i < 0) return 0; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){ans *=(n+1-j); ans /= j; ans %= MOD;} }return ans;}
template<typename T> T gcd(T a, T b){if(b == 0) return a;else return gcd(b, a%b);}
template<typename T> T lcm(T a, T b){if(b > a) swap(a, b); T g = gcd(a, b);return a / g * b;}


void solve(){
  ll mod = 998244353;
  int s[200005] = {};
  int n, k; cin >> n >> k;
  int dp[n + 1] = {};
  for(int i = 0 ; i < k; ++i){
    int l, r; cin >> l >>r;
    for(int j = l; j <= r; j++){
      s[j] = 1;
    }
  }
  set<int> box;
  for(int i = 0; i <= n; ++i){
    if(s[i]) box.insert(i);
  }
  dp[0] = 0; dp[1] = 1;
  for(int i = 2; i <= n; i++){
    for(auto val: box) {
      if(i - val < 1) continue;
      dp[i] += dp[i-val];
      dp[i] %= mod;
    }
    set<int>::iterator itr = --box.end();
    if(*itr + i >= n) box.erase(itr);
  }
  cout << dp[n] << endl;
}

int main(void){
  solve();
  return 0;
}
