#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 998244353;
int main() {
  long long int a[200005], n, k, n2 = 0, a2[200005];
  cin >> n >> k;
  for (int i = 0; i < (n + 1); i++) {
    a[i] = 0;
    a2[i] = 0;
  }
  for (int i = 0; i < k; i++) {
    int c, d;
    cin >> c >> d;
    a[c] = 1;
    a[d + 1] = -1;
  }
  for (int i = 1; i < n; i++) {
    a[i] = a[i] + a[i - 1];
    if (a[i] >= 1) {
      a2[n2] = i;
      n2++;
    }
  }
  a[1] = 1;
  for (int i = 2; i < (n + 1); i++) {
    a[i] = 0;
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < n2; j++) {
      if (i + a2[j] <= n) {
        a[i + a2[j]] = (a[i + a2[j]] + a[i]) % MOD;
      }
    }
  }
  cout << a[n] << endl;
  return 0;
}
