#include <bits/stdc++.h>
using namespace std;
static const int MOD = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  int S[200000], idx = 0;
  int dp[200010];
  for (int i = 0; i < K; i++) {
    int s, t;
    cin >> s >> t;
    for (int j = s; j <= t; j++) {
      S[idx++] = j;
    }
  }
  dp[0] = 0;
  dp[1] = 1;
  int num;
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < idx; j++) {
      num = i - S[j];
      if (num > 0) {
        dp[i] += dp[num];
      } else
        break;
      if (dp[i] > MOD) dp[i] %= MOD;
    }
  }
  cout << dp[N] << endl;
  return 0;
}
