#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
template <typename T>
void view(T e) {
  std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v) {
  for (const auto& e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>>& vv) {
  cout << endl;
  int cnt = 0;
  for (const auto& v : vv) {
    cout << cnt << "th : ";
    view(v);
    cnt++;
  }
  cout << endl;
}
const ll mod = 998244353;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
template <class T>
bool chmax(T& a, const T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll modpow(ll a, ll p) {
  ll ret = 1;
  while (p) {
    if (p & 1) {
      ret = ret * a % mod;
    }
    a = a * a % mod;
    p >>= 1;
  }
  return ret;
}
ll dp[200005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (i > 2) {
      dp[i] += dp[i - 1];
      dp[i] %= mod;
    }
    for (int j = 0; j < k; j++) {
      dp[i + l[j]] += dp[i];
      dp[i + l[j]] %= mod;
      dp[i + r[j] + 1] += (mod - dp[i]) % mod;
    }
  }
  cout << dp[n] % mod << endl;
}
