#include <bits/stdc++.h>
using namespace std;
void gogeta() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long MAX = 2 * 100000;
vector<pair<long long, long long> > v(10);
vector<long long> memo(MAX, -1);
bool isValid(long long i) {
  for (auto x : v) {
    if (i >= x.first && i <= x.second) return true;
  }
  return false;
}
long long util(long long i, long long n) {
  if (i > n) return 0;
  if (i == n) return 1;
  if (memo[i] != -1) return memo[i];
  long long ans = 0;
  for (long long d = 1; d <= n; d++) {
    if (isValid(d)) ans = (ans + util(i + d, n)) % 998244353;
  }
  return memo[i] = ans;
}
int32_t main() {
  gogeta();
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    cin >> v[i].first >> v[i].second;
  }
  memo.resize(MAX, -1);
  cout << util(1, n) << endl;
}
