#include <bits/stdc++.h>
using namespace std;
priority_queue<long> p;
long long n;
long long k;
long long ans = 0;
long long now = 0;
long long h[400005] = {0};
long long a[200005] = {0};
long long L[12] = {0};
long long R[12] = {0};
long long t = 0;
long long M = 998244353;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) cin >> L[i] >> R[i];
  for (int j = 1; j <= k; j++) {
    h[L[j] + 1]++;
    h[R[j] + 1 + 1]--;
  }
  for (int i = 2; i < n; i++) {
    now += h[i];
    if (now < 0) now += 100 * M;
    now %= M;
    for (int j = 1; j <= k; j++) {
      h[L[j] + i] = now;
      h[R[j] + i + 1] = -now;
    }
  }
  cout << ((now + h[n]) + 100 * M) % M << endl;
}
