#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
ll dp[200005];
int main() {
  int N, K;
  cin >> N >> K;
  int mod = 998244353;
  set<int> s;
  for (int i = 0; i < (K); ++i) {
    int a, b;
    cin >> a >> b;
    for (ll j = a; j <= b; ++j) s.insert(j);
  }
  dp[1] = 1;
  for (ll i = 1; i <= N; ++i) {
    bool changed = false;
    for (int num : s) {
      int ns = i + num;
      if (ns <= N) {
        (dp[ns] += dp[i]) %= mod;
        changed = true;
      } else
        break;
    }
    if (!changed) break;
  }
  cout << dp[N] << endl;
  return 0;
}
