#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
constexpr ll MOD = 998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k, l, r;
  cin >> n >> k;
  vector<int> v;
  for (int i = 0; i < k; ++i) {
    cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  int m = v.size();
  vector<ll> dp(n + 1, 0);
  dp[1] = 1LL;
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (i - v[j] <= 0) continue;
      dp[i] += dp[i - v[j]];
      dp[i] %= MOD;
    }
  }
  cout << dp[n] << endl;
}
