#include <bits/stdc++.h>
const int N = 2e5 + 10;
const int mod = 998244353;
using namespace std;
map<int, int> r;
int a[N], b[N];
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), r[a[i]] = i;
  for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
  long long ans = 1, L = 1, R = r[b[1]];
  if (R == 0) {
    puts("0");
    return;
  }
  for (int i = 1; i <= R; ++i)
    if (a[i] < b[1]) {
      puts("0");
      return;
    }
  for (int i = 2; i <= m; ++i) {
    if (r[b[i]] == 0) {
      puts("0");
      return;
    }
    int cc = 0;
    for (int j = r[b[i]]; j > R; --j) {
      if (a[j] < b[i]) break;
      cc++;
    }
    for (int j = R + 1; j <= r[b[i]]; ++j)
      if (a[j] < b[i - 1]) {
        puts("0");
        return;
      }
    ans = ans * cc % mod;
    R = r[b[i]];
  }
  for (int i = R; i <= n; ++i)
    if (a[i] < b[m]) {
      puts("0");
      return;
    }
  printf("%lld\n", ans);
}
int main() {
  int _ = 1;
  while (_--) solve();
  return 0;
}
