#include <bits/stdc++.h>
const int MOD = 998244353;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;
using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
bool paircomp(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
ll MODPOW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = MODPOW(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * MODPOW(n, m - 1)) % MOD;
  }
}
ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vl DP(2e5 + 10, -1);
set<ll> S;
ll f(ll all) {
  if (DP[all] != -1) return DP[all];
  ll ans = 0;
  if (S.count(all) != 0) ans++;
  for (auto &s : S) {
    ans += f(all - s) % MOD;
    ans %= MOD;
  }
  DP[all] = ans;
  return ans;
}
ll MODDIV(ll a, ll b) { return a * MODPOW(b, MOD - 2) % MOD; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  cin >> N >> K;
  vl L(K), R(K);
  for (ll i = 0; i < (K); i++) {
    cin >> L[i] >> R[i];
    for (ll j = (L[i]); j < (R[i] + 1); j++) {
      S.insert(j);
    }
  }
  DP[0] = 1;
  cout << MODDIV(f(N - 1), 2) << endl;
  return 0;
}
