#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int n, k, w[200005], num, f[200005] = {1};
int main() {
  cin >> n >> k;
  --n;
  for (int i = 1; i <= k; ++i) {
    int x, y;
    cin >> x >> y;
    for (int j = x; j <= y; ++j) w[++num] = j;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= num; ++j)
      if (i - w[j] >= 0) f[i] = (f[i] + f[i - w[j]]) % mod;
  cout << f[n];
  return 0;
}
