#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100;
const int mod = 998244353;
int a[maxn], b[maxn], c[maxn], p[maxn * 4], id[maxn * 4];
void creat(int l, int r, int k);
int query(int l, int r, int al, int ar, int k);
int main() {
  int n, m, i, j, k, id, pos;
  long long ans = 1;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= m; i++) scanf("%d", &b[i]);
  creat(1, n, 1);
  for (i = 1; i <= m; i++) {
    if (c[i - 1] == n) break;
    id = query(1, n, c[i - 1] + 1, n, 1);
    if (i == 1 && a[id] != b[i]) break;
    while (a[id] < b[i] && id != n) {
      c[i - 1] = id;
      id = query(1, n, id + 1, n, 1);
    }
    if (c[i - 1] < n && a[id] == b[i]) {
      c[i] = id;
      if (i != 1) ans = ans * (c[i] - c[i - 1]) % mod;
    } else
      break;
  }
  if (i <= m)
    printf("0\n");
  else
    printf("%I64d\n", ans);
  return 0;
}
void creat(int l, int r, int k) {
  if (l == r) {
    p[k] = l;
    return;
  }
  int mid = (l + r) / 2;
  creat(l, mid, 2 * k);
  creat(mid + 1, r, 2 * k + 1);
  if (a[p[2 * k]] < a[p[2 * k + 1]])
    p[k] = p[2 * k];
  else
    p[k] = p[2 * k + 1];
}
int query(int l, int r, int al, int ar, int k) {
  if (l == al && r == ar) return p[k];
  int mid = (l + r) / 2;
  if (ar <= mid)
    return query(l, r, al, ar, 2 * k);
  else if (al > mid)
    return query(mid + 1, r, al, ar, 2 * k + 1);
  else {
    int id1 = query(l, mid, al, mid, 2 * k);
    int id2 = query(mid + 1, r, mid + 1, ar, 2 * k + 1);
    return a[id1] < a[id2] ? id1 : id2;
  }
}
