#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using ll = long long;
using ld = long double;
using namespace std;
const int mod1 = 1e9 + 7;
template <typename L>
int factorise(L a) {
  int c = 0;
  int limit = sqrt(a);
  for (int i = 1; i <= limit; i++) {
    if (a % i == 0) {
      c++;
      if (i != a / i) c++;
    }
  }
  return c;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> dp(n + 1);
  dp[0] = 0;
  set<int> s;
  dp[1] = 1;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) s.insert(j);
  }
  for (int i = 2; i <= n; i++) {
    for (auto j : s) {
      if (j <= i) dp[i] = (dp[i] + dp[i - j]) % 998244353;
    }
  }
  cout << dp[n] << "\n";
}
