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