#include <bits/stdc++.h>
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 998244353;
const int N = 2e5 + 5;
vector<int> s;
int memo[N];
ll call(int n) {
  if (n == 1) return 1;
  if (n <= 0) return 0;
  if (memo[n] != -1) return memo[n];
  for (int& i : s) {
    if (i >= n) break;
    memo[n] += call(n - i);
    memo[n] %= mod;
  }
  memo[n]++;
  return memo[n];
}
void solve() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.push_back(j);
    }
  }
  sort(s.begin(), s.end());
  memset(memo, -1, sizeof(memo));
  call(n);
  cout << memo[n];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
