#include <bits/stdc++.h>
using ll = long long;
using namespace std;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template <typename Type>
inline void chmin(Type& a, Type b) {
  if (a > b) a = b;
}
template <typename Type>
inline void chmax(Type& a, Type b) {
  if (a < b) a = b;
}
template <typename Arr, typename Type>
inline void fill(Arr& arr, Type v) {
  std::fill(arr.begin(), arr.end(), v);
}
template <typename Type>
inline void sort(Type& arr) {
  std::sort(arr.begin(), arr.end());
}
template <typename Type>
inline void reverse(Type& arr) {
  reverse(arr.begin(), arr.end());
}
template <typename Type>
inline Type nth(vector<Type>& arr, size_t pos) {
  std::nth_element(arr.begin(), arr.begin() + pos, arr.end());
  return arr[pos];
}
template <typename Type>
inline void unique(Type& arr) {
  sort(arr);
  arr.erase(unique(arr.begin(), arr.end()), arr.end());
}
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<P> ranges;
  for (ll i = 0; i < (K); ++i) {
    ll L, R;
    cin >> L >> R;
    ranges.push_back(P(L, R));
  }
  vector<ll> dp(N * 3);
  dp[0] = 1;
  for (ll i = 0; i < (N); ++i) {
    for (auto& r : ranges) {
      ll L = r.first;
      ll R = r.second;
      for (ll j = L; j <= R; ++j) {
        ll idx = i + j;
        dp[idx] += dp[i];
      }
    }
  }
  ll last = dp[N - 1];
  cout << last % 998244353;
  return 0;
}
