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