#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int maxn = 2e5 + 9;
int a[maxn], b[maxn];
int main() {
  int n, m;
  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]);
  }
  long long ans = 1;
  int l = n, r = n;
  for (int i = m; i >= 1; i--) {
    while (a[r] > b[i]) r--;
    if (a[r] != b[i] || r == 0) {
      ans = 0;
      break;
    }
    l = r;
    while (a[l] >= b[i]) l--;
    if (i != 1)
      ans = ans * (r - l) % mod;
    else if (l != 0)
      ans = 0;
    r = l;
  }
  printf("%lld\n", ans);
  return 0;
}
