#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int ans = 0;
long long int dep(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 - arr[j]] %= mod;
        count[i] %= mod;
        count[i] = (count[i] + count[i - arr[j]]) % mod;
      } else if (i < arr[j])
        break;
    }
  }
  return count[N] % mod;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, r;
  cin >> n >> r;
  vector<long long int> v;
  long long int a, b;
  for (long long int i = 0; i < r; i++) {
    cin >> a >> b;
    for (long long int i = a; i <= b; i++) {
      v.push_back(i);
    }
  }
  sort(v.begin(), v.end());
  long long int x = 0;
  ans = dep(v, v.size(), n - 1);
  cout << ans << endl;
  ans = 0;
}
