#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long d(vector<long long> &dp, map<long long, long long> m, long long N,
            long long n) {
  if (n == 1) return 1;
  if (dp[n] > 0) return dp[n];
  long long nn = 0;
  for (auto p : m) {
    if (p.first >= n) break;
    nn += d(dp, m, N, n - p.first);
    nn %= mod;
  }
  dp[n] = nn;
  return nn;
}
signed main() {
  long long N, K;
  cin >> N >> K;
  map<long long, long long> m;
  for (long long i = 0; i < (long long)(K); i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) m[j]++;
  }
  vector<long long> dp(N + 1, 0);
  cout << d(dp, m, N, N) << endl;
}
