#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char ch = getchar();
  long long p = 1, data = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') p = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    data = data * 10 + (ch ^ 48);
    ch = getchar();
  }
  return p * data;
}
inline long long qpow(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = a * r;
    a = a * a;
    b >>= 1;
  }
  return r;
}
inline long long gcd(long long a, long long b) {
  if (!a || !b) return (!a) ? b : a;
  while (b ^= a ^= b ^= a %= b)
    ;
  return a;
}
inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b)
    x = 1, y = 0;
  else {
    exgcd(b, a % b, y, x);
    y -= x * (a / b);
  }
}
const int mod = 998244353, maxn = 2e5 + 5;
int a[maxn], b[maxn];
int n, m;
struct ST_map {
  int st[maxn][30], logg[maxn], bin[maxn];
  void g_st() {
    for (int i = 1; i <= n; i++) st[i][0] = a[i];
    bin[0] = 1;
    for (int i = 1; i <= 30; i++) bin[i] = bin[i - 1] * 2;
    logg[0] = -1;
    for (int i = 1; i <= n; i++) logg[i] = logg[i / 2] + 1;
    for (int i = 1; i <= logg[n]; i++)
      for (int j = 1; j <= n; j++)
        if (j + bin[i] - 1 <= n)
          st[j][i] = min(st[j][i - 1], st[j + bin[i - 1]][i - 1]);
        else
          break;
  }
  int query(int l, int r) {
    int len = r - l + 1, lg = logg[len];
    return min(st[l][lg], st[r - bin[lg] + 1][lg]);
  }
} st;
int Left[maxn];
int bs(int l, int r, int x) {
  int mid, res = -1;
  int R = r;
  while (l <= r) {
    mid = l + r >> 1;
    if (st.query(mid, R) > x)
      r = mid - 1;
    else
      l = mid + 1, res = mid;
  }
  return res;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= m; i++) b[i] = read();
  st.g_st();
  int r = n;
  for (int i = m; i >= 1; i--) {
    int mi = a[r];
    while (r > 1 && a[r - 1] >= b[i]) mi = min(mi, a[--r]);
    if (mi != b[i]) {
      puts("0");
      return 0;
    }
    Left[i] = r;
  }
  if (Left[1] != 1) {
    puts("0");
    return 0;
  }
  r = n;
  long long ans = 1;
  for (int i = m; i >= 2; i--) {
    int p = bs(Left[i], r, b[i]);
    r = p - 1;
    (ans *= p - Left[i] + 1LL) %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}
