#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MOD = 998244353;
const double EPS = 1e-9;
const double PI = acos(-1.0);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  long long N, K;
  cin >> N >> K;
  vector<long long> st;
  vector<long long> dp(N + 1, 0);
  dp[1] = 1;
  for (long long i = (0); i < (long long)(K); ++i) {
    long long L, R;
    cin >> L >> R;
    for (long long j = (L); j < (long long)(R + 1); ++j) {
      st.push_back(j);
    }
  }
  sort((st).begin(), (st).end());
  for (long long i = (2); i < (long long)(N + 1); ++i) {
    for (auto x : st) {
      if (i - x < 1) break;
      dp[i] += dp[i - x];
    }
  }
  cout << dp[N] % MOD << "\n";
}
