#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<long long> S;
  long long MOD = 998244353;
  for (int i = 0; i < (int)(K); i++) {
    long long a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) {
      S.push_back(j);
    }
  }
  vector<long long> dp(N + 5, 0);
  dp[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < S.size(); j++) {
      if (S[j] + i <= N) {
        dp[S[j] + i] += dp[i];
        dp[S[j] + i] %= MOD;
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}
