#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using ld = long double;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll l[20], r[20];
ll dp[220000];
map<ll, ll> x;
int main() {
  ll n, k, ans = 0;
  cin >> n >> k;
  for (ll i = ll(0); i < ll(k); i++) {
    cin >> l[i] >> r[i];
    for (ll j = ll(l[i]); j < ll(r[i] + 1); j++) {
      x[j] = 1;
    }
  }
  dp[1] = 1;
  for (ll i = ll(1); i < ll(n + 1); i++) {
    for (auto j : x) {
      ll p = i + j.first;
      if (p > n) break;
      if (p <= n) dp[p] = (dp[i] + dp[p]) % mod2;
    }
  }
  cout << (mod2 + dp[n]) % mod2;
}
