#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> dp(N + 10);
  set<long long> s;
  for (long long i = 0; i < K; ++i) {
    long long L, R;
    cin >> L >> R;
    for (long long j = L; j <= R; ++j) {
      s.insert(j);
    }
  }
  dp[0] = 1;
  for (int i = 0; i < N + 10; ++i) {
    for (auto num : s) {
      if (i + num < N + 10) {
        dp[i + num] += dp[i];
        dp[i + num] %= MOD;
      }
    }
  }
  cout << dp[N - 1] << endl;
}
