#include <bits/stdc++.h>
struct Vec {
  double x, y;
};
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;
}
using namespace std;
int dp[20008];
const int mod = 998244353;
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, k, p = 0;
  cin >> n >> k;
  vector<int> s;
  for (int i = (int)(0); i < (int)(k); i++) {
    int l, r;
    cin >> l >> r;
    for (int m = (int)(l); m < (int)(r + 1); m++) {
      s.push_back(m);
    }
  }
  for (int i = (int)(0); i < (int)(n); i++) dp[i] = 0;
  dp[1] = 1;
  for (int i = (int)(2); i < (int)(n + 1); i++) {
    for (auto& l : s) {
      if ((i - l) <= 0) continue;
      dp[i] += dp[i - l];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
