#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int N, K;
int L[10], R[10];
long long cnt[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(10) << fixed;
  cin >> N >> K;
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  cnt[0] = 1;
  cnt[1] = -1;
  for (int i = 0; i < N; i++) {
    if (i > 0) cnt[i] += cnt[i - 1];
    cnt[i] %= MOD;
    for (int j = 0; j < K; j++) {
      cnt[i + L[j]] += cnt[i];
      cnt[i + L[j]] %= MOD;
      cnt[i + R[j] + 1] -= cnt[i];
      cnt[i + R[j] + 1] %= MOD;
    }
  }
  cout << (cnt[N - 1] + MOD) % MOD << endl;
}
