#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
int ctoi(char c) { return c - '0'; }
int slen(string s) { return s.length(); }
int vsize(vi a) { return (int)a.size(); }
int in() {
  int x;
  cin >> x;
  return x;
}
void tf(bool ok) { cout << (ok ? "YES" : "NO") << endl; }
const ll mxn = 2e5 + 55;
const int MOD = 998244353;
ll dp[mxn];
void rrrrrrrrrrrrrresi() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> a(K, pair<int, int>());
  for (int i = 0; i < K; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(), a.end());
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < K; j++) {
      for (int k = a[j].first; k <= a[j].second; k++) {
        if (i + k >= N) break;
        dp[i + k] = ((dp[i + k] % MOD) + (dp[i] % MOD)) % MOD;
      }
    }
  }
  cout << dp[N - 1] << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int Q = 1;
  while (Q--) rrrrrrrrrrrrrresi();
  return 0;
}
