#include <bits/stdc++.h>
using namespace std;
int N, K;
int L[15], R[15];
int imos[202020];
long long now = 1;
int main() {
  cin >> N >> K;
  for (size_t i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  for (int i = 1; i <= N; i++) {
    now += imos[i];
    now %= 998244353;
    for (int j = 0; j < K; j++) {
      if (i + L[j] < 202020) {
        imos[i + L[j]] += now;
      }
      if (i + R[j] < 202020) {
        imos[i + R[j] + 1] -= now;
      }
    }
    if (i == N) {
      while (imos[N] < 0) {
        imos[N] += 998244353;
      }
      cout << imos[N] % 998244353 << endl;
    }
  }
}
