#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
using pint = pair<long long, long long>;
const long long wari = 998244353;
int main() {
  long long N, K;
  cin >> N >> K;
  set<long long> LR;
  for (int i = 0; i < K; i++) {
    long long a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
      LR.insert(i);
    }
  }
  vector<long long> dp(N + 10);
  for (int i = 0; i < dp.size(); i++) dp[i] = 0;
  dp[0] = 0;
  for (auto x : LR) {
    dp[x] = 1;
  }
  for (int i = 0; i < N - 1; i++) {
    for (auto x : LR) {
      if (i + x > N) break;
      if (dp[i] == 1) {
        dp[i + x] += 1;
        dp[i + x] %= wari;
      } else {
        dp[i + x] += dp[i];
        dp[i + x] %= wari;
      }
    }
  }
  cout << dp[N - 1] % wari << endl;
  return 0;
}
