#include <bits/stdc++.h>
using namespace std;
long long int x[1000000], y[1000000], pot[30], czy = 0, w, n, m;
char s[1000][1000];
int main() {
  long long int a, b, c, d, k, i, j, q, t, p, multi, mi;
  q = 1;
  {
    scanf("%lld%lld", &n, &m);
    for (i = 0; i < n; i++) {
      scanf("%lld", &x[i]);
    }
    for (i = 0; i < m; i++) {
      scanf("%lld", &y[i]);
    }
    for (i = 0; i < n; i++) {
      if (x[i] < y[0]) {
        printf("0\n");
        return (0);
      }
    }
    j = m - 1;
    mi = y[j];
    w = 1;
    multi = 1;
    p = 0;
    for (i = n - 1; i >= 0; i--) {
      if (x[i] < mi) p = 0;
      if (x[i] < y[j]) {
        printf("0\n");
        return (0);
      }
      if (x[i] == y[j]) {
        mi = y[j];
        w *= multi;
        w %= 998244353;
        multi = 1;
        p = 1;
        j--;
        if (j < 0) break;
      } else {
        multi += p;
      }
    }
    if (j >= 0)
      printf("0\n");
    else
      printf("%lld\n", w);
  }
  return (0);
}
