#include <bits/stdc++.h>
const int maxn = 2e5 + 5;
const int mod = 998244353;
using namespace std;
long long dp[maxn], l[maxn], r[maxn], sum[maxn];
void solve() {
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  dp[1] = sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i > l[j])
        dp[i] = (dp[i] + sum[i - l[j]] - sum[max(i - r[j] - 1, 0ll)]) % mod;
    }
    sum[i] = (dp[i] + sum[i - 1]) % mod;
  }
  cout << dp[n] << '\n';
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
