#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> s;
  for (int i = 0; i < K; i++) {
    int li, ri;
    cin >> li >> ri;
    for (int j = li; j <= ri; j++) {
      s.push_back(j);
    }
  }
  int slen = s.size();
  vector<int> routnum(N, 0);
  routnum[0] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < slen; j++) {
      if (i - s[j] >= 0) {
        routnum[i] += routnum[i - s[j]];
        routnum[i] %= mod;
      }
    }
  }
  cout << routnum[routnum.size() - 1] << endl;
}
