#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
const ll MOD = 1000000007;
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;
}
signed main() {
  ll n;
  cin >> n;
  ll k;
  cin >> k;
  vl nx(0);
  for (long long i = 0; i < (long long)(k); i++) {
    ll a, b;
    cin >> a >> b;
    for (long long j = a; j < (long long)(b + 1); j++) nx.push_back(j);
  }
  vl dp(n + 1);
  dp[1] = 1;
  for (long long i = 1; i < (long long)(n); i++) {
    for (auto c : nx) {
      if (i + c <= n) {
        dp[i + c] += dp[i];
        dp[i + c] %= 998244353;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
