#include <bits/stdc++.h>
int n, k;
int l[11], r[11];
long long int dp[200010];
std::vector<int> vec;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &l[i], &r[i]);
    for (int j = l[i]; j <= r[i]; j++) {
      vec.push_back(j);
    }
  }
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (auto& j : vec) {
      if (i + j < n) dp[i + j] = (dp[i + j] + dp[i]) % 998244353;
    }
  }
  printf("%lld\n", dp[n - 1]);
}
