#include <bits/stdc++.h>
using namespace std;
constexpr int kMod = 998244353;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> av(n);
  for (auto&& e : av) {
    cin >> e;
  }
  map<int, int> bv;
  for (int i = 0; i < m; ++i) {
    int v;
    cin >> v;
    bv[v] = 0;
  }
  vector<int> cnt(n);
  cnt[n - 1] = av[n - 1];
  for (int i = n - 1; i-- > 0;) {
    cnt[i] = min(av[i], cnt[i + 1]);
  }
  for (int i = n; i-- > 0;) {
    if (bv.count(cnt[i])) {
      bv[cnt[i]]++;
    }
  }
  if (cnt[0] != begin(bv)->first) {
    cout << 0 << endl;
    return 0;
  } else {
    bv.erase(begin(bv));
  }
  int64_t res = 1;
  for (auto&& [k, v] : bv) {
    res = (v * res) % kMod;
  }
  cout << res << endl;
  return 0;
}
