#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, k;
  cin >> n >> k;
  map<ll, ll> mp;
  ll l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (ll j = l; j <= r; j++) mp[j]++;
  }
  vector<ll> dp(n, 0);
  dp[0] = 1;
  int step;
  for (int i = 0; i < n; i++) {
    for (auto u : mp) {
      step = u.first;
      if (i - step < 0) break;
      dp[i] = dp[i] + dp[i - step];
      dp[i] = dp[i] % 998244353;
    }
  }
  cout << dp[n - 1] << endl;
}
