#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1e9 + 10;
const ll MOD = 998244353;
const ll LINF = 1e18;
ll dp[11][200005];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  dp[0][0] = 1;
  vpll lr(k);
  for (long long i = (long long)(0); i < (long long)(k); ++i)
    cin >> lr[i].first >> lr[i].second;
  vll v;
  for (long long i = (long long)(0); i < (long long)(k); ++i) {
    ll l, r;
    tie(l, r) = lr[i];
    vll w;
    for (ll j = l; j <= r; j++) w.push_back(j);
    vb u(n);
    u[0] = 1;
    for (auto e : w) {
      for (long long j = (long long)(0); j < (long long)(n); ++j) {
        if (j + e < n) {
          (dp[i + 1][j + e] += dp[i][j]) %= MOD;
          u[j + e] = 1;
        }
      }
    }
    for (auto e : v) {
      for (long long j = (long long)(0); j < (long long)(n); ++j) {
        if (j + e < n) (dp[i + 1][j + e] += dp[i + 1][j]) %= MOD;
      }
    }
    for (auto e : w) {
      for (long long j = (long long)(0); j < (long long)(n); ++j)
        if (u[j] == 0) {
          if (j + e < n) (dp[i][j + e] += dp[i][j]) %= MOD;
        }
    }
    for (long long j = (long long)(0); j < (long long)(n); ++j)
      (dp[i + 1][j] += dp[i][j]) %= MOD;
    for (auto e : w) v.push_back(e);
  }
  cout << dp[k][n - 1] << endl;
}
