#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using namespace std;
constexpr ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  vector<ll> dp(n);
  dp[0] = 1;
  for (int i = (0), i_end_ = (k); i < i_end_; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) s.push_back(j);
  }
  for (int i = (1), i_end_ = (n); i < i_end_; i++) {
    for (int j = (0), j_end_ = (s.size()); j < j_end_; j++) {
      int buf = i - s[j];
      if (buf >= 0) {
        if (dp[buf] > 0) {
          dp[i] += dp[buf];
        }
      }
    }
  }
  cout << dp[n - 1] % MOD << endl;
  return 0;
}
