#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
vector<ll> v;
ll n;
ll dp[200005];
int freq[200005], have[200005];
void init() {
  for (int i = int(0); i <= int(200000); i++) dp[i] = -1;
}
ll go(int cur) {
  if (cur > n) return 0;
  if (cur == n) return 1;
  if (dp[cur] != -1) return dp[cur];
  ll ans = 0;
  for (auto i : v)
    if (cur + i <= n) ans = (ans + go(cur + i)) % 998244353;
  return dp[cur] = ans % 998244353;
}
void solve() {
  init();
  int k;
  cin >> n >> k;
  for (int i = 0; i < int(k); i++) {
    int a, b;
    cin >> a >> b;
    freq[a]++;
    freq[b + 1]--;
  }
  for (int i = int(1); i <= int(200000); i++) {
    have[i] = have[i - 1] + freq[i];
  }
  for (int i = int(1); i <= int(200000); i++) {
    if (have[i]) v.push_back(i);
  }
  cout << go(1) % 998244353;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
