#include <bits/stdc++.h>
using namespace std;
const long long siz = 2e5 + 10;
const long long SIZ = 1e6 + 10;
const long long mod = 998244353;
const long long maxx = 2e9;
const long long MAXX = 1e18;
const string file = "3";
long long n;
vector<long long> mov;
long long f[siz];
long long dp(long long pos) {
  if (pos == n) {
    return 1;
  }
  long long &res = f[pos];
  if (res != -1) {
    return res;
  }
  res = 0;
  long long p =
      upper_bound((mov).begin(), (mov).end(), n - pos) - mov.begin() - 1;
  for (long long i = p; i >= 0; i--) {
    long long nxt = pos + mov[i];
    if (nxt <= n) {
      (res += dp(nxt)) %= mod;
    }
  }
  return res;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      mov.push_back(j);
    }
  }
  sort((mov).begin(), (mov).end());
  memset(f, -1, sizeof(f));
  cout << dp(1) << "\n";
  return 0;
}
