#include <bits/stdc++.h>
using namespace std;
long long mini[200010], a[200010], b[200010];
long long now, L[200010], R[200010], n, m, ans;
bool flag;
const long long MOD = 998244353;
int main() {
  scanf("%lld%lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
  }
  mini[n] = a[n];
  for (int i = n - 1; i >= 1; i--) {
    mini[i] = min(mini[i + 1], a[i]);
  }
  now = 1;
  for (long long i = 1; i <= n; i++) {
    if (mini[i] == b[now]) {
      R[now] = max(R[now], i);
      if (mini[i - 1] < mini[i]) L[now] = i;
      if (mini[i + 1] > mini[i] && now < m) now++;
    }
  }
  flag = true;
  ans = 1;
  if (mini[1] != b[1]) flag = false;
  for (int i = 1; i <= m; i++) {
    if ((!L[i]) || (!R[i])) {
      flag = false;
    } else {
      if (i > 1) {
        ans = (ans * (R[i] - L[i] + 1)) % MOD;
      }
    }
  }
  if (flag) {
    printf("%lld\n", ans);
  } else
    printf("0\n");
}
