#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long mod2 = 998244353;
vector<long long> ten(200005, 0);
long long dp[200005];
int main() {
  long long n, k;
  cin >> n >> k;
  long long l, r;
  dp[1] = 0;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    ten[l] = 1;
    ten[r + 1] = -1;
  }
  for (int i = 1; i < 200005; i++) {
    ten[i] += ten[i - 1];
  }
  vector<long long> key;
  for (int i = 1; i < 200005; i++) {
    if (ten[i] > 0) {
      key.push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    dp[i] = 0;
  }
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto id : key) {
      if (i - id > 0) {
        dp[i] += dp[i - id] % mod2;
        dp[i] %= mod2;
      }
    }
  }
  cout << dp[n] % mod2 << endl;
  return 0;
}
