#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const ll INF = 2e15;
template <class T>
void print(const T& t) {
  cout << t << endl;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  ll n, k;
  cin >> n >> k;
  ll mod = 998244353;
  vector<Pll> s(0);
  for (ll i = 0; i < (ll)(k); i++) {
    ll l, r;
    cin >> l >> r;
    s.push_back(make_pair(l, r));
  }
  vl dp(n + 1, 0);
  dp[1] = 1;
  dp[2] = -1;
  for (ll i = 1; i <= n; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= mod;
    for (ll j = 0; j < k; j++) {
      if (i + s[j].first <= n) {
        dp[i + s[j].first] += dp[i];
      }
      if (i + s[j].second + 1 <= n) {
        dp[i + s[j].second + 1] -= dp[i];
      }
    }
  }
  dp[n] %= mod;
  print(dp[n]);
}
