#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 998244353;
int n, k;
int l[N], r[N];
bool st[N];
int f[N * 2];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; ++j) st[j] = true;
  }
  f[1] = 1;
  for (int i = 1; i <= n; ++i) {
    if (i != 1 && !f[i]) continue;
    for (int j = 1; i + j <= n; ++j) {
      if (st[j]) f[i + j] = (f[i + j] + f[i]) % mod;
    }
  }
  cout << f[n] << '\n';
  return 0;
}
