#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long N, K, l[11], r[11], memo[200010], prefix[400010];
void Input() {
  cin >> N >> K;
  for (long long i = 1; i <= K; i++) {
    cin >> l[i] >> r[i];
  }
}
void Solve() {
  memset(prefix, 0, sizeof prefix);
  prefix[N] = 1;
  memo[N] = 1;
  for (long long i = N - 1; i >= 1; i--) {
    long long total = 0;
    for (long long j = 1; j <= K; j++) {
      long long nl = l[i], nr = r[i];
      total += (prefix[i + nl] - prefix[i + nr + 1]) % MOD;
      total = total % MOD;
    }
    memo[i] = total;
    prefix[i] = (prefix[i + 1] + total) % MOD;
  }
  cout << memo[1] << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Input();
  Solve();
}
