#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int l[20], r[20];
  const long long mod = 998244353;
  set<int> move;
  vector<long long> masu(500100, 0);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) {
      move.insert(j);
    }
  }
  masu[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (auto &&e : move) {
      masu[i + e] += masu[i];
      masu[i + e] %= mod;
    }
  }
  cout << masu[n] << endl;
}
