#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<ll>> merge(vector<vector<ll>>& intervals) {
  sort(intervals.begin(), intervals.end());
  vector<vector<ll>> merged;
  for (auto interval : intervals) {
    if (merged.empty() || (merged.back()[1] < interval[0])) {
      merged.push_back({interval[0], interval[1]});
    } else {
      merged.back()[1] = max(merged.back()[1], interval[1]);
    }
  }
  return merged;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, k;
  cin >> n >> k;
  vector<vector<ll>> intervals;
  while (k--) {
    ll a, b;
    cin >> a >> b;
    intervals.push_back({a, b});
  }
  vector<vector<ll>> merged = merge(intervals);
  vector<ll> steps;
  for (auto x : merged) {
    ll a = x[0];
    ll b = x[1];
    for (ll i = a; i <= b; i++) steps.push_back(i);
  }
  sort(steps.begin(), steps.end());
  int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  for (ll i = 2; i <= n; i++) {
    for (ll j = 0; j < steps.size(); j++) {
      if (i - steps[j] > 0) {
        dp[i] = (dp[i] % 998244353 + dp[i - steps[j]] % 998244353) % 998244353;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
