#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
void solve() {
  const long long mod = 998244353;
  int N, K;
  cin >> N >> K;
  set<int> s;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) s.insert(j);
  }
  ll dp[200005] = {0};
  dp[0] = 1;
  for (int i = 1; i < N; i++) {
    for (auto v : s) {
      if (i - v >= 0) {
        dp[i] += dp[i - v];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[N - 1] << endl;
}
int main(int argc, char const *argv[]) {
  solve();
  return 0;
}
