#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 998244353;
int l[maxn], r[maxn], v[maxn], dp[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  int m = 1;
  for (int i = 0; i < k; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      v[m++] = j;
    }
  }
  dp[1] = 1;
  for (int j = 1; j <= n; ++j) {
    for (int i = 1; i < m; ++i) {
      dp[j] = (dp[j] + dp[j - v[i]]) % mod;
    }
  }
  cout << dp[n];
  return 0;
}
