#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, K, a, b;
  cin >> N >> K;
  vector<__int64_t> count(N + 1, 0);
  count[1] = 1;
  vector<int> v(0);
  for (int i = 0; i < K; i++) {
    cin >> a >> b;
    for (int j = a; j <= b; j++) {
      v.push_back(j);
    }
  }
  for (int i = 2; i <= N; i++) {
    for (int j : v) {
      if (i - j > 0) {
        count[i] += count[i - j];
        count[i] = count[i] % 998244353;
      }
    }
  }
  cout << count[N] % 998244353 << endl;
}
