#include <bits/stdc++.h>
using namespace std;
template <typename T>
void inputArray(T *a, int start, int end) {
  for (int i = start; i <= end; ++i) cin >> a[i];
}
template <typename T>
void printArray(T *a, int start, int end) {
  for (int i = start; i <= end; ++i) cout << *(a + i) << ' ';
}
void ruffleSort(int *a, int n) {
  unsigned seed = 0;
  shuffle(a, a + n, default_random_engine(seed));
  sort(a, a + n);
}
const int N = 2 * 1e5 + 5;
int a[N];
int ans;
void solve(int pos, int n, vector<int> &s) {
  for (auto it = s.begin(); it != s.end(); ++it) {
    if ((pos + (*it)) < n)
      solve(pos + (*it), n, s);
    else if ((pos + (*it)) == n)
      ++ans;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, k;
  cin >> n >> k;
  int l, r;
  for (int i = 0; i <= k; ++i) {
    cin >> l >> r;
    for (int i = l; i <= r; ++i) ++a[i];
  }
  vector<int> s;
  for (int i = 0; i <= N - 2; ++i) {
    if (a[i]) s.push_back(i);
  }
  solve(1, n, s);
  cout << ans % 998244353;
  return 0;
}
