#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
ll mod = 998244353;

int main() {
  ll n, k; cin >> n >> k;
  vector<bool> s(200010,false);
  rep(i,k){
    int sta, end;
    cin >> sta >> end;
    for(int j = sta; j<=end; j++){
      s.at(j) = true;
    }
  }

  //rep(i,n) if(s.at(i)) cout << i << endl;

  vector<ll> dp(200010);
  dp[1] = 1;
  for(int i = 2; i <= n; i++){
    for(int j = 1; j < i; j++){
      if(s.at(j)) dp[i] += dp[i-j];
      dp[i] %= mod;
    }
  }
  cout << dp[i] << endl;
}
