#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
  ll n, k, l, r, i, j, mod = 998244353;
  set<ll> s;
  cin >> n >> k;
  vector<ll> dp(n);
  for (i = 0; i < k; i++) {
    cin >> l >> r;
    for (j = l; j <= r; j++) s.insert(j);
  }
  dp[0] = 1;
  for (i = 1; i < n; i++) {
    for (auto x : s) {
      if (x <= i)
        dp[i] = (dp[i] + dp[i - x]) % mod;
      else
        break;
    }
  }
  cout << dp[n - 1] << endl;
}
