#include <bits/stdc++.h>
using namespace std;
const long long N = 1E5 + 5;
const long long mod = 998244353;
long long dp[N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> idx;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) idx.push_back(j);
  }
  sort(idx.begin(), idx.end());
  idx.erase(unique(idx.begin(), idx.end()), idx.end());
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j : idx) {
      if (i - j >= 1) {
        dp[i] += dp[i - j];
        dp[i] %= mod;
      } else
        break;
    }
  }
  cout << dp[n];
  return 0;
}
