#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
void read(int& val) {
  int x = 0;
  int bz = 1;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  if (c == '-') {
    bz = -1;
    c = getchar();
  }
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  val = x * bz;
}
const int mod = 998244353;
const int maxn = 2e6 + 10;
int n, m;
int a[maxn], b[maxn];
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 1; i <= m; i++) read(b[i]);
  reverse(a + 1, a + 1 + n);
  reverse(b + 1, b + 1 + m);
  a[n + 1] = -1;
  int mi = a[1];
  long long ans = 1;
  int pos = 1;
  while (pos <= n && mi > b[1]) {
    pos++;
    mi = min(mi, a[pos]);
  }
  if (pos > n | mi < b[1]) {
    puts("0");
    return 0;
  }
  int l = 2;
  while (1) {
    if (l > m) {
      for (int i = pos; i <= n; i++) {
        if (a[i] < b[m]) {
          puts("0");
          return 0;
        }
      }
      break;
    }
    bool f = true;
    int npos = pos;
    while (pos <= n && mi != b[l]) {
      pos++;
      mi = min(mi, a[pos]);
      if (f && mi < b[l - 1]) {
        f = 0;
        ans = ans * (pos - npos) % mod;
      }
    }
    if (pos > n) {
      puts("0");
      return 0;
    }
    l++;
  }
  printf("%lld\n", ans);
  return 0;
}
