#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 998244353;
const long long INF = 1LL << 60;
// 入力
ll n, A;

ll dp[200001][200001];

void solve(vector<ll> a, ll target) {
  // memset(dp, 0, sizeof(dp));  // 一旦すべて 0 に
  dp[0][0] = 1;  // dp[0][0] だけ 1 に

  ll n = a.size();
  for (ll i = 0; i <= target; i++) {
    for (ll j = 0; j <= target; ++j) {
      for (ll k = 0; k < n; k++) {
        if (j + a[k] < 200001) {
          dp[i + 1][j + a[k]] += dp[i][j];
          dp[i + 1][j + a[k]] %= MOD;
        } else {
          break;
        }
      }
    }
  }
  ll ans = 0;
  for (ll i = 0; i <= target; i++) {
    ans += dp[i][target - 1] % MOD;
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector<ll> a;
  for (ll i = 0; i < k; i++) {
    ll l, r;
    cin >> l >> r;
    for (ll j = l; j <= r; j++) {
      a.push_back(j);
    }
  }
  solve(a, n);
}
