#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll K;
  cin >> K;
  vl L(K);
  vl R(K);
  for (ll i = 0; i < K; i++) {
    cin >> L.at(i) >> R.at(i);
  }
  vl dp(2 * N, 0);
  dp.at(N) = 1;
  vl c;
  for (ll i = 0; i < K; i++) {
    for (ll j = 0; j < R.at(i) - L.at(i) + 1; j++) {
      c.push_back(j + L.at(i));
    }
  }
  ll count = c.size();
  sort((c).begin(), (c).end());
  for (ll j = (N + 1); j < (2 * N); j++) {
    for (ll i = 0; i < count; i++) {
      dp.at(j) += dp.at(j - c.at(i));
    }
  }
  cout << dp.at(2 * N - 1) % MOD9 << endl;
}
