#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#pragma GCC optimize("O2")
const ll MOD = 998244353;
int n, k;
vector<int> ds, chk;
map<int, ll> memo;
ll inline solve(int i) {
  if (i == n) {
    return 1;
  }
  if (memo.count(i)) return memo[i];
  ll ans = 0;
  for (int j = 0; j < ds.size() && i + ds[j] <= n; j++) {
    ans = (ans + solve(i + ds[j])) % MOD;
  }
  return memo[i] = ans;
}
void test_case() {
  cin >> n >> k;
  chk.resize(n + 2);
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) chk[j] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (chk[i] == 1) ds.push_back(i);
  }
  cout << solve(1);
  return;
}
int main() {
  ios::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.tie(0);
  test_case();
  return 0;
}
