#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long MOD = 998244353;
int dp[2 * 10 + 100];
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  for (int i = 0; i < (int)(K); i++) {
    cin >> L[i] >> R[i];
  }
  vector<int> Wa(N + 100);
  dp[1] = 1;
  Wa[1] = 1;
  for (int i = 1; i <= N; i++) {
    long long num = 0;
    for (int j = 0; j < (int)(K); j++) {
      int l = max(0, i - R[j] - 1);
      int r = i - L[j];
      if (r < 0) continue;
      dp[i] += Wa[r] - Wa[l];
      while (dp[i] < 0) {
        dp[i] += MOD;
      }
      dp[i] %= MOD;
    }
    Wa[i] = dp[i] + Wa[i - 1];
    while (Wa[i] < 0) {
      Wa[i] += MOD;
    }
    Wa[i] %= MOD;
  }
  cout << dp[N] << endl;
}
