#include <bits/stdc++.h>
using namespace std;
void solve() {
  int i, j;
  int n, k;
  cin >> n >> k;
  vector<int> pos(n + 1, 0), dp(n + 1, 0);
  for (int i = 0; i < k; ++i) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; ++j) {
      pos[j] = 1;
    }
  }
  dp[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j < i; ++j) {
      if (pos[j]) {
        dp[i] += dp[i - j];
        dp[i] %= 998244353;
      }
    }
  }
  printf("%d\n", dp[n]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  while (T--) {
    solve();
  }
}
