#include <bits/stdc++.h>
using namespace std;
long long Ceil(long long val, long long div) { return (val + div - 1) / div; }
long long CeilN(long long val, long long div) { return Ceil(val, div) * div; }
long long FloorN(long long x, long long n) { return (x - x % n); }
bool IsOdd(long long x) { return ((x & 1) == 1); }
bool IsEven(long long x) { return ((x & 1) == 0); }
template <class T>
bool chmax(T& a, T b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, T b) {
  if (a >= b) {
    a = b;
    return 1;
  }
  return 0;
}
void Solve() {
  long long N, K;
  cin >> N >> K;
  vector<long long> s;
  for (long long i = 0; i < (long long)K; ++i) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      s.emplace_back(j);
    }
  }
  sort((s).begin(), (s).end());
  static long long dp[6];
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  for (long long i = 0; i < (long long)N + 1; ++i) {
    for (auto j : s) {
      long long now = dp[i];
      if (0 < now) {
        long long n = i + j;
        if (N < n) break;
        dp[n] += now;
        dp[n] %= 998244353;
      }
    }
  }
  cout << dp[N] << endl;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Solve();
  return 0;
}
