#include <bits/stdc++.h>
using namespace std;
int n, m, a[200010], b[200010], pt[200010];
const int mod = 998244353;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  int j = pt[m + 1] = n + 1;
  for (int i = m; i >= 1; i--) {
    int minn = 2e9;
    while (j > 1 && a[j - 1] >= b[i]) minn = min(minn, a[--j]);
    pt[i] = j;
    if (minn != b[i]) {
      printf("0");
      return 0;
    }
  }
  if (j > 1) {
    printf("0");
    return 0;
  }
  long long ans = 1;
  for (int i = 2; i <= m; i++) {
    int j = pt[i + 1], minn = 2e9;
    while (minn != b[i]) minn = min(minn, a[--j]);
    ans = ans * (j - pt[i] + 1) % mod;
  }
  printf("%lld", ans);
  return 0;
}
