#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> flag(200005, 0);
  int l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) flag[j] = 1;
  }
  vector<ll> dp(n, 0);
  dp[0] = 1;
  int step;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= i; j++) {
      if (flag[j] = 0) continue;
      step = j;
      if (i - step < 0) continue;
      dp[i] = dp[i] + dp[i - step];
      dp[i] = dp[i] % 998244353;
    }
  }
  cout << dp[n - 1] << endl;
}
