#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;
int main() {
  ll n, k, l, r;
  ll mod = 998244353;
  cin >> n >> k;
  vector<ll> vec;
  for (int i = 0; i < (int)(k); i++) {
    cin >> l >> r;
    for (ll i = l; i <= r; i++) vec.push_back(i);
  }
  sort(vec.begin(), vec.end());
  vector<ll> dp(n + 1, 0);
  dp[1] = 1;
  for (ll i = 1; i < n; i++) {
    if (dp[i] > 0) {
      for (auto d : vec) {
        if (i + d <= n) {
          dp[i + d] = (dp[i + d] + dp[i]) % mod;
        } else {
          break;
        }
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
