#include <bits/stdc++.h>
using namespace std;
const long long mxn = 1e5;
const long long mod = 998244353;
long long pow(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b % 2 != 0) r = (r * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return r;
}
const int siz = 5e5 + 20;
long long fact[siz], inv[siz];
void pre() {
  fact[0] = 1;
  inv[0] = pow(fact[0], mod - 2);
  for (int i = 1; i < siz; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
}
int spf[10];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < mxn; i++) spf[i] = i;
  for (int i = 4; i < mxn; i += 2) spf[i] = 2;
  for (int i = 3; i * i < mxn; i++) {
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  vector<int> v;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) v.push_back(j);
  }
  long long dp[n];
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (v[j] <= i) dp[i] = (dp[i] + dp[i - v[j]]) % mod;
    }
  }
  cout << dp[n - 1];
}
