#include <bits/stdc++.h>
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;
}
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int mod = 998244353;
const int inf = (1 << 29);
int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int> > rng;
  for (int i = 0; i < (K); i++) {
    int l, r;
    cin >> l >> r;
    r++;
    rng.push_back(make_pair(l, r));
  }
  vector<int> dp(N);
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < (N); i++) {
    if (i > 0) {
      dp[i] += dp[i - 1];
      dp[i] %= mod;
    }
    for (int j = 0; j < (K); j++) {
      int l, r;
      tie(l, r) = rng[j];
      if (i + l < N) {
        dp[i + l] += dp[i];
        dp[i + l] %= mod;
      }
      if (i + r < N) {
        dp[i + r] -= dp[i];
        dp[i + r] %= mod;
      }
    }
  }
  cout << dp[N - 1] % mod << endl;
  return 0;
}
