#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  set<int> st;
  ll tot = 0;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      if (!st.count(j)) tot += j;
      st.insert(j);
    }
  }
  vector<int> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto x : st) {
      if (i - x < 0) continue;
      dp[i] = (dp[i] + dp[i - x]) % MOD;
    }
  }
  cout << dp[n] << '\n';
}
