#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;
const ll mod = 998244353;
ll L[11], R[11];
vector<ll> sum;
ll dp[202020];
int main() {
  int N, K;
  cin >> N >> K;
  for (int i = (0); (i) < (int)(K); ++(i)) {
    cin >> L[i] >> R[i];
    for (int j = L[i]; j <= R[i]; ++j) sum.push_back(j);
  }
  sort(sum.begin(), sum.end());
  fill(dp, dp + N + 1, -1);
  int len = sum.size();
  dp[1] = 1LL;
  for (int i = 1; i < N; ++i) {
    if (dp[i] == -1) continue;
    for (int j = 0; j < len; ++j) {
      if (i + sum[j] <= N) {
        if (dp[i + sum[j]] == -1) dp[i + sum[j]] = 0;
        dp[i + sum[j]] = (dp[i + sum[j]] + dp[i]) % mod;
      } else {
        break;
      }
    }
    while (len >= 0 and i + 1 + sum[len - 1] > N) {
      len--;
    }
  }
  if (dp[N] == -1) dp[N] = 0;
  cout << dp[N] % mod << endl;
}
