#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
using ll = long long;
const int mod = 998244353;
const ll inf = 1e18 + 1;
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> L(K), R(K);
  for (ll i = 0; i < (K); i++) {
    cin >> L[i] >> R[i];
  }
  vector<ll> dp(N + 1, 0);
  set<ll> S;
  for (ll i = 0; i < (K); i++) {
    for (int j = L[i]; j <= R[i]; j++) {
      S.insert(j);
    }
  }
  for (ll i = 0; i < (N + 1); i++) {
    for (auto j : S) {
      if (i - j >= 0) {
        dp[i] += dp[i - j];
        dp[i] %= mod;
      } else {
        break;
      }
    }
  }
  cout << dp[N];
}
