#include <bits/stdc++.h>
using namespace std;
long long int MOD = 998244353;
void run_case() {
  long int n;
  int k;
  cin >> n >> k;
  set<long int> v;
  long int a, b;
  for (int i = 0; i < k; i++) {
    cin >> a >> b;
    for (long int j = a; j <= b; j++) {
      if (v.count(j) == 0) v.insert(j);
    }
  }
  long long int *h;
  h = new long long int[n];
  h[n - 1] = 1;
  for (long int i = n - 2; i >= 0; i--) {
    h[i] = 0;
    for (auto x : v) {
      if (i + x <= n - 1) h[i] += h[i + x];
      h[i] = h[i] % MOD;
    }
  }
  cout << h[0] << endl;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  run_case();
}
