#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> move;
  long long ans[n];
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      move.push_back(j);
    }
  }
  for (int i = 0; i < n; i++) {
    ans[i] = 0;
  }
  long long mod = 998244353;
  sort(move.begin(), move.end());
  int size = move.size();
  ans[0] = 1;
  for (int i = 1; i < n; i++) {
    int cou = 0;
    for (int j = 0; j < size; j++) {
      if (i - move[j] < 0) {
        break;
      } else {
        ans[i] += ans[i - move[j]];
        ans[i] %= mod;
      }
    }
  }
  cout << ans[n - 1] << endl;
}
