#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> move;
  for (int i = 0; i < (k); i++) {
    int first, last;
    cin >> first >> last;
    for (int ni = first; ni <= last; ni++) {
      move.push_back(ni);
    }
  }
  map<int, int> table;
  table[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (const auto& mi : move) {
      table[i] += table[i - mi];
      table[i] %= mod;
    }
  }
  cout << table[n] << endl;
}
