#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main() {
  long long N, K;
  cin >> N >> K;
  long long L, R;
  vector<long long> vec;
  for (long long i = 0; i < K; i++) {
    cin >> L >> R;
    for (long long j = L; j <= R; j++) {
      vec.push_back(j);
    }
  }
  sort(vec.begin(), vec.end());
  long long last = N / vec[0] + 1;
  vector<long long> dp(N + 1, 0);
  dp[1] = 1;
  long long ans = 0;
  for (long long i = 1; i <= last; i++) {
    vector<long long> dp_n(N + 1, 0);
    for (long long j = 1; j <= N; j++) {
      for (long long k = 0; k < (long long)vec.size(); k++) {
        if (j + vec[k] <= N) {
          dp_n[j + vec[k]] = (dp_n[j + vec[k]] + dp[j]) % mod;
        } else {
          break;
        }
      }
    }
    ans = (ans + dp_n[N]);
    swap(dp, dp_n);
  }
  cout << ans << endl;
}
