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