#include <bits/stdc++.h>
using namespace std;
long long countWays(vector<long long> arr, long long m, long long N) {
  long long count[N + 1];
  memset(count, 0, sizeof(count));
  count[0] = 1;
  for (long long i = 1; i <= N; i++)
    for (long long j = 0; j < m; j++)
      if (i >= arr[j]) {
        count[i] += count[i - arr[j]];
        count[i] %= 998244353;
      }
  return count[N] % 998244353;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long tc = 1;
  while (tc--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> v;
    while (k--) {
      long long l, r;
      cin >> l >> r;
      for (long long i = l; i <= r; i++) v.emplace_back(i);
    }
    long long sz = v.size();
    long long ans = countWays(v, sz, n - 1);
    cout << ans << "\n";
  }
}
