#include <bits/stdc++.h>
using namespace std;
void boost() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int a[200001], b[200001];
long long solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) cin >> a[(n - 1) - i];
  for (int i = 0; i < (m); ++i) cin >> b[(m - 1) - i];
  long long np = 1;
  int ai = 0, s;
  for (int bi = 0; bi < (m); ++bi) {
    while (ai < n && a[ai] > b[bi]) ai++;
    if (ai >= n || b[bi] != a[ai]) return 0;
    s = ai;
    while (ai < n && a[ai] >= b[bi]) ai++;
    if (ai >= n && bi == m - 1) return np;
    if (ai >= n) return 0;
    np = np * (ai - s);
    np = np % 998244353;
  }
  if (ai == n) return np;
  return 0;
}
int main() {
  boost();
  int T;
  T = 1;
  while (T--) {
    cout << solve() << "\n";
  }
}
