#include <bits/stdc++.h>
using namespace std;
long long int const mod = 998244353;
std::mt19937 rng(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
int rand_rng(int l, int r) {
  uniform_int_distribution<int> p(l, r);
  return p(rng);
}
int arr1[10000009];
int parent[10000009];
vector<long long int> sieve;
void sievefun(long long int n) {
  for (long long int i = 2; i <= n; i++) {
    if (arr1[i] == 0) {
      parent[i] = i;
      for (long long int j = i * i; j <= n; j += i) {
        if (arr1[j] == 0) parent[j] = i;
        arr1[j] = 1;
      }
    }
  }
}
long long int power(long long int x, long long int y, long long int m) {
  long long int temp;
  if (y == 0 || x == 1) return 1;
  temp = power(x, y / 2, m) % m;
  if (y % 2 == 0)
    return ((temp) * (temp)) % m;
  else
    return (((x) % m) * ((temp * temp) % m)) % m;
}
int const N = 2000009;
int main() {
  sievefun(10000000);
  int T;
  T = 1;
  while (T--) {
    long long int n, m;
    cin >> n >> m;
    int a[n + 3], b[m + 3];
    int dp[n + 3];
    for (int i = 0; i < (int)n; i++) cin >> a[i];
    for (int i = 0; i < (int)m; i++) cin >> b[i];
    dp[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      dp[i] = min(dp[i + 1], a[i]);
    }
    int l = -1;
    if (dp[0] < b[0]) {
      cout << "0\n";
      continue;
    }
    b[m] = 1000000009;
    int ind = 1;
    int pos = -1;
    long long int ans = 1;
    vector<long long int> vec;
    ind = m - 1;
    for (int i = 0; i < (int)n; i++) vec.push_back(dp[i]);
    for (int i = 0; i < (int)m; i++) {
      if (!i) {
        if (upper_bound(vec.begin(), vec.end(), b[i]) ==
            lower_bound(vec.begin(), vec.end(), b[i])) {
          ans = 0;
          break;
        }
      } else {
        ans *= (upper_bound(vec.begin(), vec.end(), b[i]) -
                lower_bound(vec.begin(), vec.end(), b[i]));
        ans %= mod;
      }
    }
    cout << ans << "\n";
  }
}
