#include <bits/stdc++.h>
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {}
int n, k;
long long dp[N], sum[N];
int l[N], r[N];
inline void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) scanf("%d%d", &l[i], &r[i]);
  dp[1] = sum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= k; ++j)
      dp[i] += (sum[max(0, i - l[j])] - sum[max(0, i - r[j] - 1)]) % mod,
          dp[i] %= mod;
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  cout << dp[n];
}
int main() {
  TIME__START = clock();
  int Test = 1;
  while (Test--) {
    solve();
  }
  TIME__END = clock();
  program_end();
  return 0;
}
