#include <bits/stdc++.h>
using namespace std;
const int N = 2e5, K = 10, mod = 998244353;
int n, k, l[K], r[K], dp[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cin >> n >> k, dp[1] = 1;
  for (int i = 0; i < k; ++i) cin >> l[i] >> r[i];
  for (int i = 1; i < n; ++i)
    for (int j = 0; j < k; ++j)
      for (int u = i + l[j], v = i + r[j]; u <= n and u <= v; ++u)
        dp[u] += dp[i], dp[u] %= mod;
  cout << dp[n];
}
