#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll N, K;
const ll mm = 998244353;
int main() {
  cin >> N >> K;
  vector<pair<ll, ll>> tile(K);
  for (ll i = 0; i < K; i++) cin >> tile[i].first >> tile[i].second;
  vector<ll> Msum(N + 1, 0);
  Msum[1] = 1;
  for (ll i = 2; i <= N; i++) {
    for (ll j = 0; j < K; j++) {
      ll s1 = i - tile[j].first;
      ll s2 = i - tile[j].second;
      if (s1 <= 0 && s2 <= 0) continue;
      if (s2 <= 0 && s1 > 0) s2 = 1;
      Msum[i] += Msum[s1] - Msum[s2 - 1];
      Msum[i] %= mm;
    }
    Msum[i] += Msum[i - 1];
    Msum[i] %= mm;
  }
  cout << Msum[N] - Msum[N - 1] << endl;
}
