#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;
void print() { cout << endl; }
template <typename Head, typename... Tail>
void print(Head head, Tail... tail) {
  cout << head;
  if (sizeof...(Tail) > 0) cout << " ";
  print(tail...);
}
void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
  cout << head;
  print0(tail...);
}
int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> dp(200003, 0);
  vector<ll> exist(200003, 0);
  vector<ll> moves;
  for (ll i = 0; i < K; i++) {
    ll l, r;
    cin >> l >> r;
    for (ll j = l; j <= r; j++) {
      moves.push_back(j);
    }
  }
  sort(moves.begin(), moves.end());
  dp[1] = 1;
  for (ll i = 1; i <= N; i++) {
    for (auto j : moves) {
      if (i + j > N) {
        break;
      }
      dp[i + j] = (dp[i + j] + dp[i]) % 998244353;
    }
  }
  print(dp[N]);
}
