#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k, x, y;
  cin >> n >> k;
  vector<bool> jump(n + 1);
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    for (int i = x; i <= y; i++) jump[i] = 1;
  }
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (!jump[j]) continue;
      x = i + j;
      if (x > n) break;
      dp[x] = (dp[x] + dp[i]) % 998244353;
    }
  }
  cout << dp[n];
  return 0;
}
