#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < (k); i++) {
    cin >> l[i] >> r[i];
  }
  set<int> st;
  for (int i = 0; i < (k); i++) {
    for (int j = l[i]; j <= r[i]; j++) st.insert(j);
  }
  vector<ll> dp(n + 5);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto a : st) {
      if (i > a) dp[i] += dp[i - a];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
