#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v;
  long long mod = 998244353;
  for (long long i = 0; i < k; i++) {
    long long a, b;
    cin >> a >> b;
    for (long long j = a; j <= b; j++) v.push_back(j);
  }
  sort(v.begin(), v.end());
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j = 0; j < v.size(); j++) {
      if (i - v[j] > 0) {
        dp[i] = (dp[i - v[j]] + dp[i]) % mod;
      } else
        break;
    }
  }
  cout << dp[n] << endl;
}
int main() { solve(); }
