#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N][2];
int cnt;
long long f[N];
vector<int> v;
pair<int, int> q[12];
const int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  f[1] = 1;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    q[i] = {l, r};
  }
  sort(q + 1, q + 1 + k);
  for (int i = 1; i <= k; i++)
    for (int j = q[i].first; j <= q[i].second; j++) v.push_back(j);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i - v[j] <= 0) break;
      f[i] += f[i - v[j]];
      f[i] %= mod;
    }
  }
  cout << f[n] << endl;
  return 0;
}
