#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, k, ans[200001];
  set<long long> p;
  memset(ans, 0, sizeof(ans));
  ans[1] = 1;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    long long a, b;
    cin >> a >> b;
    for (long long j = a; j <= b; j++) p.insert(j);
  }
  for (long long i = 1; i <= n; i++) {
    for (auto j : p) {
      if (i > j) ans[i] = (ans[i] + ans[i - j]) % 998244353;
    }
  }
  cout << ans[n];
}
