#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
int N, K;
vector<pint> LR;
vector<ll> dp;
ll f(int n) {
  if (dp[n] != -1) return dp[n];
  ll res = 0;
  int flag = 0;
  for (ll i = 0; i < (ll)(K); i++) {
    if (flag) break;
    for (int a = LR[i].first; a <= LR[i].second; a++) {
      if (n - a < 1) {
        flag = 1;
        break;
      }
      res += f(n - a) % 998244353;
      res %= 998244353;
    }
  }
  res %= 998244353;
  return dp[n] = res;
}
int main() {
  cin >> N >> K;
  LR.resize(K);
  for (ll i = 0; i < (ll)(K); i++) {
    int l, r;
    cin >> l >> r;
    LR[i] = {l, r};
  }
  sort(LR.begin(), LR.end());
  dp.resize(N + 1);
  for (ll i = 1; i <= (ll)(N); i++) dp[i] = -1;
  dp[1] = 1;
  cout << f(N) % 998244353 << endl;
}
