#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < (int)(k); i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) a.push_back(j);
  }
  sort(a.begin(), a.end());
  vector<long long> road(n + 1);
  road[n] = 1;
  for (int res = 1; res < n; res++) {
    int now = n - res;
    int x = min(res, int(a.size()));
    for (int i = 0; i < (int)(x); i++) {
      if (a[i] <= res) road[now] += road[now + a[i]] % MOD;
    }
  }
  cout << road[1] % MOD;
}
