#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  set<long long> s;
  for (int i = (int)(0); i < (int)(k); i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      s.insert(i);
    }
  }
  long long dp[200005];
  dp[1] = 1;
  priority_queue<long long, vector<long long>, greater<long long>> q;
  q.push(1);
  while (!q.empty()) {
    long long p = q.top();
    q.pop();
    for (auto x : s) {
      if (p + x > n) break;
      if (dp[p + x] == 0) q.push(p + x);
      dp[p + x] += dp[p];
      dp[p + x] %= MOD;
    }
  }
  cout << dp[n] << endl;
}
