#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 200010;
const long long mod = 998244353;
int n, k;
long long dp[N], pre[N];
pair<int, int> a[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie(0);
  int minpos = 1e9;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> a[i].first >> a[i].second;
    minpos = min(minpos, a[i].first);
  }
  dp[1] = 1;
  pre[1] = 1;
  for (int i = 1 + minpos; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i] = (dp[i] + (pre[max(0, i - a[j].first)] -
                        pre[max(0, i - a[j].second - 1)])) %
              mod;
    }
    pre[i] = (pre[i - 1] + dp[i]) % mod;
  }
  cout << (dp[n] + mod) % mod << '\n';
  return 0;
}
