#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> m) {
  cout << "(" << m.first << ", " << m.second << ")";
  return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const map<T, U> m) {
  ll c = 0;
  cout << "{ ";
  for (auto &(i) : (m)) cout << i << (c++ == m.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
  cout << "{ ";
  for (ll(i) = 0LL; (i) < (ll)(v.size()); (i)++)
    cout << v[i] << (i == v.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
template <typename T>
ostream &operator<<(ostream &s, const list<T> &v) {
  ll c = 0;
  cout << "{ ";
  for (auto &(i) : (v)) cout << i << (c++ == v.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
int main(void) {
  ll N, K;
  cin >> N >> K;
  vector<ll> S;
  for (ll(i) = 0LL; (i) < (ll)(K); (i)++) {
    ll l, r;
    cin >> l >> r;
    for (ll(j) = (ll)(l); (j) <= (ll)(r); (j)++) S.push_back(j);
  }
  vector<ll> dp(N);
  dp.front() = 1;
  for (ll(i) = 0LL; (i) < (ll)(N); (i)++) {
    if (dp[i] == 0) continue;
    for (auto &(j) : (S)) {
      ll temp = (i + j) % 998244353LL;
      if (temp < dp.size()) (dp[temp] += dp[i]) %= 998244353LL;
    }
  }
  cout << dp.back() << endl;
  return 0;
}
