#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long int N, K;
  cin >> N >> K;
  vector<long long int> v;
  for (long long int i = 0; i < (long long int)(K); ++i) {
    long long int L, R;
    cin >> L >> R;
    for (long long int j = L; j <= (long long int)(R); ++j) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  vector<long long int> cnt(N + 1, 0);
  cnt[0] = 1;
  for (long long int i = 1; i <= (long long int)(N); ++i) {
    for (long long int x : v) {
      if (i - x < 0) break;
      cnt[i] += cnt[i - x];
      cnt[i] %= 998244353;
    }
  }
  cout << cnt[N - 1] << endl;
  return 0;
}
