#include <bits/stdc++.h>
const long long MOD = 998244353;
const long long INF = 1061109567;
int main() {
  long long n, k;
  std::vector<long long> s;
  std::cin >> n >> k;
  for (long long i = 0; i < k; ++i) {
    long long temp_1, temp_2;
    std::cin >> temp_1 >> temp_2;
    for (long long j = temp_1; j <= temp_2; ++j) {
      s.push_back(j);
    }
  }
  std::vector<long long> key(n, 0);
  key[0] = 1;
  for (long long i = 0; i < n; ++i) {
    for (auto v : s) {
      if (i + v < n && key[i] > 0) {
        key[i + v] += key[i];
        key[i + v] %= MOD;
      }
    }
  }
  std::cout << key[n - 1] << std::endl;
  return 0;
}
