#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll> >;
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> A(n + 1, 0), B(n, 0);
  B[0] = 1;
  for (ll i = 0; i < (ll)(k); i++) {
    ll l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) A[j] = 1;
  }
  for (ll i = 1; i <= n; i++) {
    for (ll j = 0; j < i; j++) {
      if (A[i - j] == 1) B[i] += B[j];
    }
    B[i] %= 998244353;
  }
  cout << B[n - 1];
  return 0;
}
