#include <bits/stdc++.h>
using namespace std;
const int N = 200009;
int n, k, a[N], t = 0;
long long dp[N];
long long dfs(int x) {
  if (dp[x] != -1) return dp[x];
  dp[x] = 0;
  for (int i = 0; i < t; i++) {
    if (x + a[i] > n) break;
    (dp[x] += dfs(x + a[i])) %= 998244353;
  }
  return dp[x];
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) a[t++] = j;
  }
  sort(a, a + t);
  for (int i = 1; i <= n; i++) dp[i] = -1;
  dp[n] = 1;
  cout << dfs(1);
  return 0;
}
