#include <bits/stdc++.h>
using namespace std;
long long int n, k;
long long int dp[100001];
bool boosted[100001];
vector<long long int> valid;
long long int solve(long long int i) {
  if (i == n - 1) return dp[i] = 1;
  if (dp[i] != -1) return dp[i];
  long long int ret = 0;
  for (auto const &j : valid) {
    long long int next = i + j + 1;
    if (next >= n) break;
    ret = (ret + solve(next)) % 998244353;
  }
  return dp[i] = ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (long long int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    a--, b--;
    for (long long int i = a; i <= b; i++) boosted[i] = true;
  }
  for (long long int i = 0; i < n; i++)
    if (boosted[i]) valid.push_back(i);
  memset(dp, -1, sizeof(dp));
  solve(0);
  cout << dp[0] << endl;
}
