#include <bits/stdc++.h>
using namespace std;
int l[200010], r[200010], a[200010], b[200010], n, m;
long long sum = 1;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  int p = n - 1;
  for (int i = m - 1; i >= 0; i--) {
    while (p >= 0 && a[p] != b[i] && a[p] > b[i]) p--;
    r[i] = p;
    while (p >= 0 && a[p] >= b[i]) p--;
    l[i] = p;
    if (i > 0)
      sum = 1LL * sum * (r[i] - l[i]) % 998244353;
    else {
      if (l[i] != -1 || r[i] == -1) sum = 0;
    }
  }
  printf("%lld\n", sum);
}
