#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
int32_t main() {
  long long int t = 1;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int a[k][2];
    for (long long int i = 0; i < k; i++) cin >> a[i][0] >> a[i][1];
    vector<long long int> dp(n + 1, 0);
    vector<long long int> prev(n + 1, 0);
    dp[1] = 1;
    prev[1] = 1;
    for (long long int i = 2; i <= n; i++) {
      for (long long int j = 0; j < k; j++) {
        long long int l = i - a[j][0];
        long long int r = i - a[j][1] - 1;
        if (l <= 0) {
          continue;
        }
        if (r < 0) {
          r = 0;
        }
        dp[i] =
            (dp[i] % 998244353 + (prev[l] - prev[r]) % 998244353) % 998244353;
      }
      prev[i] = (dp[i] + prev[i - 1]) % 998244353;
    }
    cout << dp[n] << endl;
  }
}
