#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  const long long mod = 998244353;
  long long N, K;
  cin >> N >> K;
  vector<long long> Number(2 * K + 1);
  for (long long i = 1; i <= 2 * K; i++) {
    cin >> Number[i];
  }
  vector<long long> dp(N + 1);
  dp[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = Number[2 * j - 1]; k <= Number[2 * j]; k++) {
        if (i + k <= N) {
          dp[i + k] = dp[i + k] + dp[i];
          if (dp[i + k] > mod) {
            dp[i + k] = dp[i + k] % mod;
          }
        } else {
          break;
        }
      }
    }
  }
  if (dp[N] >= mod) {
    dp[N] = dp[N] % mod;
  }
  cout << dp[N] << endl;
}
