#include <bits/stdc++.h>
using namespace std;
long long d[200005], mod = 998244353;
vector<long long> a;
set<long long> s;
long long solve(long long x) {
  cout << x << endl;
  if (d[x]) return d[x];
  long long sum = 0;
  for (auto i : a) {
    if (x > i) sum += solve(x - i), sum %= mod;
  }
  d[x] = sum % mod;
  return d[x];
}
int main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    long long x, y;
    cin >> x >> y;
    for (int j = x; j <= y; j++) {
      s.insert(j);
    }
  }
  for (auto i : s) {
    a.push_back(i);
  }
  d[1] = 1;
  cout << solve(n) << endl;
}
