#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  const ll mod = 998244353;
  int N, K;
  cin >> N >> K;
  vector<int> S;
  for (int i = 0; i < K; ++i) {
    int L, R;
    cin >> L >> R;
    for (int s = L; s <= R; ++s) {
      S.push_back(s);
    }
  }
  sort(S.begin(), S.end());
  vector<ll> dp(N);
  dp[0] = 1;
  for (int k = 1; k < N; ++k) {
    for (int d : S) {
      if (d <= k) {
        dp[k] += dp[k - d];
        dp[k] %= mod;
      }
    }
  }
  cout << dp[N - 1] << endl;
}
