#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
vector<long long> dp;
vector<int> S;
long long DP(int n, vector<long long> &dp, vector<int> S) {
  if (n == 1) {
    return 1;
  }
  if (dp[n] > 0) return dp[n];
  long long res = 0;
  for (int i = 0; i < S.size(); i++) {
    if (n - S[i] >= 1) {
      res += DP(n - S[i], dp, S);
      res %= MOD;
    }
  }
  return dp[n] = res;
}
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> S;
  for (int i = 0; i < K; i++) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j <= R; j++) {
      S.push_back(j);
    }
  }
  for (int i = 0; i <= N; i++) {
    dp.push_back(0);
  }
  cout << DP(N, dp, S) << endl;
}
