#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long sum[100010], dp[100010];
pair<long long, long long> a[15];
signed main() {
  long long n, k, i, j, p;
  cin >> n >> k;
  for (i = 1; i <= k; i++) cin >> a[i].first >> a[i].second;
  sort(a + 1, a + k + 1);
  dp[1] = 1;
  for (i = 2; i <= n; i++) {
    for (j = 1; j <= k; j++)
      sum[j] = (sum[j] + mod - dp[max(0ll, i - a[j].second - 1)] +
                dp[max(0ll, i - a[j].first)]) %
               mod;
    for (j = 1; j <= k; j++) dp[i] = (dp[i] + sum[j]) % mod;
  }
  cout << dp[n];
  return 0;
}
