#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 1000000007;
const int64_t tmpMod = 998244353;
int main() {
  int64_t N, k;
  cin >> N >> k;
  vector<int> s(0);
  vector<int64_t> A(N + 1, 0);
  A[0] = 0;
  A[1] = 1;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int k = a; k <= b; k++) {
      s.push_back(k);
    }
  }
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < s.size(); j++) {
      if (i >= s[j]) A[i] += A[i - s[j]];
      A[i] %= 998244353;
    }
  }
  cout << A[N] << endl;
}
