#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 998244353;

int main() {
  ll n, k, ans = 0, l, r;
  set<ll> st;
  cin >> n >> k;
  ll dp[n] = {};
  dp[0] = 1;
  rep(i, k) {
    cin >> l >> r;
    while (l <= r) st.insert(l++);
  }
  for (int i = 0; i < n; ++i) {
    for (ll t : st) {
      if (i + t < n) (dp[i + t] += dp[i]) %= mod;
    }
  }

  cout << dp[n - 1] << endl;
  return 0;
}