#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const ll INF = 2e15;
template <class T>
void print(const T& t) {
  cout << t << endl;
}
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  ll n, k;
  cin >> n >> k;
  ll mod = 998244353;
  vl s(0);
  for (ll i = 0; i < (ll)(k); i++) {
    ll l, r;
    cin >> l >> r;
    for (ll i = l; i <= r; i++) {
      s.push_back(i);
    }
  }
  sort(s.begin(), s.end());
  vl dp(n + 1, 0);
  dp[1] = 1;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 0; j < ((int)s.size()); j++) {
      if (i - s[j] < 0) {
        break;
      }
      dp[i] += dp[i - s[j]];
      dp[i] %= mod;
    }
  }
  print(dp[n]);
}
