#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
int const MOD = 998244353;
int const NMAX = 2e5 + 11;
int const KMAX = 12;
int n, k;
ll dp[NMAX][KMAX];
ii directions[KMAX];
inline ll add(ll a, ll b) { return ((a % MOD) + (b % MOD)) % MOD; }
ll solve(void) {
  dp[1][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= k; ++j) {
      auto &ans = dp[i][j];
      ans = dp[i][j - 1];
      auto [l, r] = directions[j];
      for (int d = l; d <= r; ++d) {
        if (i - d < 1) break;
        ans = add(ans, dp[i - d][j]);
      }
    }
  }
  return accumulate(dp[n] + 1, dp[n] + k + 1, 0LL, add);
}
int main(void) {
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    int l, r;
    cin >> l >> r;
    directions[i] = {l, r};
  }
  cout << solve() << endl;
  return 0;
}
