#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  set<long long> st;
  for (int i = 0; i < k; i++) {
    long long a, b;
    cin >> a >> b;
    for (long long j = a; j <= b; j++) st.insert(j);
  }
  vector<long long> vec;
  for (auto it = st.begin(); it != st.end(); it++) {
    long long p = *it;
    vec.push_back(p);
  }
  long long p = vec.size();
  long long ans[n + 1];
  for (long long i = 0; i <= n; i++) ans[i] = 0;
  ans[0] = 0;
  ans[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j = 0; j < p; j++) {
      if (i - vec[j] < 1) break;
      ans[i] += ans[i - vec[j]];
    }
    ans[i] %= 998244353;
  }
  cout << ans[n] % 998244353 << endl;
}
