#include <bits/stdc++.h>
using namespace std;
void nope() {
  printf("0\n");
  exit(0);
}
const long long MOD = 998244353;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ara[n];
  int arb[m];
  for (int bAD = 0; bAD < n; bAD++) scanf("%d", ara + bAD);
  ;
  for (int bAD = 0; bAD < m; bAD++) scanf("%d", arb + bAD);
  ;
  int bind[m];
  int cur = n - 1;
  for (int i = m - 1; i >= 0; i--) {
    while (ara[cur] != arb[i] && cur >= 0) {
      if (ara[cur] < arb[i]) nope();
      cur--;
    }
    if (cur < 0) nope();
    bind[i] = cur;
  }
  long long ans = 1;
  for (int i = 0; i < bind[0]; i++) {
    if (ara[i] < arb[0]) nope();
  }
  for (int x = 0; x < m - 1; x++) {
    int t = 1;
    for (int i = bind[x + 1] - 1; i >= bind[x] + 1; i--) {
      if (ara[i] >= arb[x + 1])
        t++;
      else
        break;
    }
    ans = (ans * t) % MOD;
  }
  printf("%lld\n", ans);
}
