#include <bits/stdc++.h>
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> L(K), R(K);
  vector<long long> walk(0);
  for (int i = 0; i < K; i++) {
    cin >> L.at(i) >> R.at(i);
    for (int j = L.at(i); j < R.at(i) + 1; j++) {
      walk.push_back(j);
    }
  }
  vector<long long> dp(N + 10, 0);
  dp[1] = 1;
  for (int i = 1; i < N + 1; i++) {
    for (int j = 0; j < walk.size(); j++) {
      if ((i + walk[j]) <= N) {
        dp[i + walk[j]] += dp[i];
        dp[i + walk[j]] %= MOD2;
      }
    }
  }
  cout << dp[N] << endl;
}
