#include <bits/stdc++.h>
using namespace std;
long long int calc(vector<long long int> arr, long long int m,
                   long long int N) {
  long long int count[N + 1];
  memset(count, 0, sizeof(count));
  count[0] = 1;
  for (long long int i = 1; i <= N; i++)
    for (long long int j = 0; j < m; j++)
      if (i >= arr[j])
        count[i] =
            (count[i] % 998244353 + count[i - arr[j]] % 998244353) % 998244353;
  return count[N];
}
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> v;
  for (long long int i = 0; i < k; i++) {
    long long int l, r;
    cin >> l >> r;
    if (l != r) {
      for (long long int j = l; j <= r; j++) v.push_back(j);
    } else
      v.push_back(l);
  }
  long long int size = v.size();
  cout << calc(v, size, n - 1);
}
