#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  set<long long> st;
  for (int i = 0; i < (k); ++i) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; ++j) st.insert(j);
  }
  vector<long long> m;
  for (long long i = 1; i <= n; ++i) {
    if (st.count(i)) m.push_back(i);
  }
  vector<long long> dp(n + 1, 0);
  dp[0] = 1;
  for (int i = 1; i < (n); ++i) {
    for (auto step : m) {
      if (i - step < 0) continue;
      dp[i] = (dp[i] + dp[i - step]) % mod;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
