#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 10;
const int MOD = 998244353;
map<int, int> las;
int n, m, a[MAXN], b[MAXN], f[MAXN][21];
long long dp[MAXN];
void init() {
  int nlog = (int)log2(n);
  for (int j = 1; j <= nlog; j++)
    for (int i = 1; i <= n; i++)
      if ((i + (1 << j) - 1) <= n)
        f[i][j] = min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
}
int query(int s, int e) {
  int nlog = (int)log2(e - s + 1);
  return min(f[s][nlog], f[e - (1 << nlog) + 1][nlog]);
}
int bin(int x) {
  int l = 1, r = n;
  while (l <= r) {
    int mid = ((l + r) >> 1);
    int tmp = query(mid, n);
    if (tmp >= x)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return l - 1;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    las[a[i]] = i;
    f[i][0] = a[i];
  }
  init();
  bool flag = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    int tmp = las[b[i]];
    if (tmp == 0 || query(las[b[i]], n) < b[i] ||
        (i == 1 && query(1, las[b[i]]) < b[i]))
      flag = 0;
  }
  if (m == 1 && flag) {
    printf("1\n");
    return 0;
  }
  if (flag == 0) {
    printf("0\n");
    return 0;
  }
  dp[m + 1] = 1;
  for (int i = m; i > 1; i--) {
    long long r = las[b[i]];
    long long l = bin(b[i]);
    dp[i] = dp[i + 1] * (r - l) % MOD;
  }
  printf("%lld\n", dp[2]);
  return 0;
}
