#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j < r + 1; j++) {
      a.push_back(j);
    }
  }
  long long dp[n + 1];
  dp[0] = 1;
  for (long long i = 1; i < n; i++) {
    dp[i] = 0;
    for (long long j = 0; j < a.size(); j++) {
      if (i >= a[j]) {
        dp[i] += dp[i - a[j]];
        dp[i] = dp[i] % 998244353;
      }
    }
  }
  cout << dp[n - 1] << '\n';
}
