#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2E5 + 5;
const int MOD = 998244353;
int n, k;
int l[20], r[20];
long long dp[MAXN], sum[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= k; i++) cin >> l[i] >> r[i];
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++)
    for (int j = 1; j <= k; j++) {
      if (i - l[j] >= 0) {
        dp[i] += sum[i - l[j]] - sum[max(0, i - r[j] - 1)];
        dp[i] = (dp[i] % MOD + MOD) % MOD;
        sum[i] = (sum[i - 1] + dp[i]) % MOD;
      }
    }
  cout << dp[n];
  return 0;
}
