#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
unordered_map<int, long long> mp;
vector<int> v;
long long cal(int n) {
  if (mp.find(n) != mp.end()) return mp[n];
  long long ans = 0;
  for (int i = 0; i < v.size(); i++)
    if (n - v[i] >= 1) ans += cal(n - v[i]);
  ans %= mod;
  mp[n] = ans;
  return ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> h(n + 1, false);
  vector<long long> dp(n + 1, 0);
  int l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) h[j] = true;
  }
  for (int i = 0; i < n + 1; i++)
    if (h[i]) v.push_back(i);
  mp[1] = 1;
  cout << cal(n) << '\n';
  return 0;
}
