#include <bits/stdc++.h>
using namespace std;
int n, m, a[301010], b[301010], mn[301010];
map<long long, long long> v;
int md = 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]);
  mn[n + 1] = 2e9;
  for (int i = n; i >= 1; i--) mn[i] = min(mn[i + 1], a[i]), v[mn[i]]++;
  long long ans = 1;
  if (mn[1] != b[1])
    ans = 0;
  else {
    for (int i = 2; i <= m; i++) ans = ans * v[b[i]] % md;
  }
  printf("%lld", ans);
  return 0;
}
