#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, f, g, n, m, k, t, x, h, w, p, q, y;
string str = "";
long long mod = 998244353;
const int N = 3009;
void solve() {
  cin >> n >> k;
  vector<long long> st;
  for (int i = 0; i < k; i++) {
    cin >> a >> b;
    for (int j = a; j <= b; j++) st.push_back(j);
  }
  sort(st.begin(), st.end());
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long a : st) {
      if (a >= i) break;
      dp[i] += dp[i - a];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  int cases = 1;
  while (cases--) solve();
  return 0;
}
