#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const vl dx = {1, 0, -1, 0, 1, 0, -1, 0};
const vl dy = {0, 1, 0, -1, 0, 1, 0, -1};
template <typename T>
T input() {
  T x;
  cin >> x;
  return x;
}
void Yes(bool ans) { cout << (ans ? "Yes" : "No") << endl; }
void YES(bool ans) { cout << (ans ? "YES" : "NO") << endl; }
ll ceil(ll a, ll b) { return (a + b - 1) / b; }
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  for (ll i = 0; i < n; i++) {
    res = res * x % mod;
  }
  return res;
}
ll MODpow(ll x, ll n) {
  ll res = 1;
  for (ll i = 0; i < n; i++) {
    res = res * x % MOD;
  }
  return res;
}
int main() {
  ll n, k;
  cin >> n >> k;
  ll mod = 998244353;
  vl add(0);
  for (ll i = 0; i < (ll)k; i++) {
    ll l, r;
    cin >> l >> r;
    for (ll j = (ll)l; j < (ll)r + 1; j++) add.push_back(j);
  }
  sort(add.begin(), add.end());
  add.erase(unique(add.begin(), add.end()), add.end());
  vl dp(n + 1, 0);
  dp[0] = 1;
  for (ll i = 0; i < (ll)n; i++) {
    for (ll j = 0; j < (ll)ll(add.size()); j++) {
      if (i - add[j] >= 0) {
        dp[i] += dp[i - add[j]];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n - 1] << endl;
}
