#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 Graph = vector<vector<int>>;
const ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<P> a;
  for (int i = 0; i < (k); i++) {
    int l, r;
    cin >> l >> r;
    a.emplace_back(l, r);
  }
  vector<ll> dp(200005, 0);
  dp[0] = 1;
  dp[1] = 1;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (k); j++) {
      int l = a[j].first;
      int r = a[j].second;
      for (; l <= r; ++l) {
        dp[i + 1 + l] += dp[i + 1];
        dp[i + 1 + l] %= MOD;
      }
    }
  cout << dp[n] << endl;
  return 0;
}
