#include <bits/stdc++.h>
using namespace std;
const int NMAX = 200005;
const int MOD = 998244353;
int N, M;
int a[NMAX], b[NMAX], suff[NMAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> M;
  for (int i = 1; i <= N; ++i) cin >> a[i];
  for (int i = 1; i <= M; ++i) cin >> b[i];
  suff[N] = a[N];
  for (int i = N - 1; i >= 1; --i) suff[i] = min(suff[i + 1], a[i]);
  int cnt = 0;
  for (int i = 1, j = 1; i <= N; ++i) {
    if (suff[i] == b[j]) {
      ++cnt;
      ++j;
      if (j > M) break;
    }
  }
  if (suff[1] < b[1] || cnt < M) {
    cout << 0 << "\n";
    return 0;
  }
  long long answer = 1;
  b[M + 1] = (1 << 30);
  suff[N + 1] = (1 << 30);
  vector<pair<int, int> > v;
  for (int i = 1, j = 1, p; i <= N; ++j) {
    while (suff[i] < b[j + 1]) ++i;
    p = i;
    while (suff[p] == b[j + 1] && suff[p + 1] == b[j + 1]) ++p;
    v.push_back(make_pair(i, p));
  }
  for (auto& i : v) answer = 1LL * answer * (i.second - i.first + 1) % MOD;
  cout << answer << "\n";
  return 0;
}
