#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> V;
  for (ll i = 0; i < (K); i++) {
    int L, R;
    cin >> L >> R;
    for (int i = L; i <= R; i++) {
      V.push_back(i);
    }
  }
  vector<long long> dp(200010, 0);
  dp[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (auto v : V) {
      if (i + v > N) continue;
      dp[i + v] += dp[i];
      dp[i + v] %= 998244353;
    }
  }
  cout << dp[N] << endl;
}
