#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; };
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; };
long long mod(long long a, long long b) { return (a + b - 1) / b; };
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
signed main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  vector<long long> table(n + 10, 0);
  vector<pair<long long, long long> > S;
  for (long long(i) = 0; i < (k); i++) {
    long long l, r;
    cin >> l >> r;
    S.push_back(pair<long long, long long>(l, r));
  }
  vector<long long> can(n + 10, 0);
  can[1] = 1;
  for (long long i = 1; i <= n; i++) {
    if (can[i]) {
      for (long long(j) = 0; j < (S.size()); j++) {
        for (long long r = S[j].first; r <= S[j].second; r++) {
          if (i + r > n) break;
          can[i + r] += can[i];
          can[i + r] %= 998244353;
        }
      }
    }
  }
  cout << can[n] << "\n";
  return 0;
}
