#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int N = 2e5 + 30, mod = 998244353;
long long int dp[N];
vector<long long int> a;
int main() {
  long long int n, k;
  cin >> n >> k;
  for (long long int i = 0; i < k; i++) {
    long long int l, r;
    cin >> l >> r;
    for (long long int i = l; i < r + 1; i++) a.push_back(i);
  }
  sort(a.begin(), a.end());
  dp[1] = 1;
  long long int s = a.size();
  for (long long int i = 2; i < n + 1; i++) {
    long long int j = 0;
    while (j < s && a[j] < i) {
      dp[i] += dp[i - a[j]];
      dp[i] %= mod;
      j++;
    }
  }
  cout << dp[n] << '\n';
}
