#include <bits/stdc++.h>
using namespace std;
int a[202020], b[202020], ma[202020], mi[202020];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int j = 1; j <= m; j++) {
    scanf("%d", &b[j]);
  }
  int now = n;
  for (int j = m; j >= 1; j--) {
    ma[j] = 0;
    while (a[now] >= b[j] && now > 0) {
      while (now > 0 && a[now] > b[j]) {
        now--;
      }
      if (a[now] == b[j]) {
        ma[j] = max(ma[j], now);
        now--;
      }
    }
    if (now > 0) mi[j] = now;
  }
  long long ans = 1;
  if (!ma[1] || now > 0) {
    printf("0");
    return 0;
  }
  for (int j = 2; j <= m; j++) {
    if (!ma[j]) {
      printf("0");
      return 0;
    }
    (ans *= (ma[j] - mi[j])) %= 998244353;
  }
  printf("%I64d", ans);
  return 0;
}
