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

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> dp(N, 0);
  dp.at(0) = 1;
  vector<int> S;
  int x, y;
  const int mod =998244353;
  
  rep(i, K){
    cin >> x >> y;
    for(int i=x; i<=y; i++) S.push_back(i);
  }
  S.sort(S.begin(), S.end());
  rep(i, N){
    for(auto e:S){
      if(i+e<N){
        dp.at(i+e) += dp.at(i);
        dp.at(i+e) %= mod;
      }else break;
    }
  }
  cout << dp.at(N-1) << endl;
  return 0;
}


