#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const ll mod = 998244353;
int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  ll dp[200000 + 5];
  dp[0] = 1;
  vector<ll> sp;
  for (int i = 0; i < (int)k; ++i) {
    ll l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      sp.push_back(j);
    }
  }
  sort(sp.begin(), sp.end());
  for (int i = 1; i < n; ++i) {
    ll ind = 0;
    while (sp[ind] <= i && ind < sp.size()) {
      dp[i] += dp[i - sp[ind]];
      dp[i] %= mod;
      ind++;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
