#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
int N, K, L[123], R[123];
int A[412345], sum[412345];
int shift = 200000;
int main() {
  cin >> N >> K;
  for (long long i = 0; i < (K); ++i) cin >> L[i] >> R[i];
  A[shift] = 1;
  sum[shift] = 1;
  for (long long i = 0; i < (N - 1); ++i) {
    int c = i + 1;
    for (long long i = 0; i < (K); ++i) {
      A[shift + c] += sum[shift + c - L[i]] - sum[shift + c - R[i] - 1];
      A[shift + c] %= 998244353;
    }
    sum[shift + c] = sum[shift + c - 1] + A[shift + c];
    sum[shift + c] %= 998244353;
  }
  cout << (A[shift + N - 1] + 998244353) % 998244353 << endl;
  return 0;
}
