#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
const int N = 1e6 + 5;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) a.push_back(j);
  }
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp));
  int sz = a.size();
  dp[0] = 1, dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < sz; j++) {
      if (i - a[j] >= 1) dp[i] = (dp[i] % mod + dp[i - a[j]] % mod) % mod;
    }
  }
  cout << dp[n] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) solve();
  return 0;
}
