#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<bool> LR(N + 1, false);
  vector<int> S;
  vector<long long> DP(N, 0);
  for (int i = 0; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    S.push_back(l);
    S.push_back(r);
  }
  sort(S.begin(), S.end());
  DP[0] = 1;
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j < K; ++j) {
      for (int k = S[j * 2]; k <= S[j * 2 + 1]; ++k) {
        if (i - k >= 0) DP[i] = (DP[i] + DP[i - k]) % MOD;
      }
    }
  }
  cout << DP[N - 1] << endl;
}
