#include <bits/stdc++.h>
using ll = long long;
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;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
template <class T>
set<T> Union(set<T>& rsettA, set<T>& rsettB) {
  set<T> settUnion(rsettA);
  for (typename set<T>::iterator itt = rsettB.begin(); itt != rsettB.end();
       itt++) {
    settUnion.insert(*itt);
  }
  return settUnion;
}
void Print(set<int>& rseti) {
  for (set<int>::iterator iti = rseti.begin(); iti != rseti.end(); iti++) {
    printf("%3d ", *iti);
  }
  printf("\n");
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  set<int> s, t;
  for (int i = 0, i_len = (k); i < i_len; ++i) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) {
      t.insert(j);
    }
    s = Union(s, t);
    t.clear();
  }
  vector<ll> dp(n);
  for (int i = 0, i_len = (n); i < i_len; ++i) dp[i] = 0;
  dp[0] = 1;
  int MOD = 998244353;
  for (int i = 0, i_len = (n); i < i_len; ++i) {
    std::set<int>::iterator it = s.begin();
    while (it != s.end()) {
      if (i + *it >= n) {
        break;
      }
      dp[i + *it] += dp[i];
      dp[i + *it] %= MOD;
      *it++;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
