#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 998244353;
int a[N];
int b[N];
int suffix[N];
map<int, int> cnt;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int i;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= m; i++) cin >> b[i];
  suffix[n + 1] = 0x3f3f3f3f;
  for (i = n; i >= 1; i--) {
    suffix[i] = min(suffix[i + 1], a[i]);
    cnt[suffix[i]]++;
  }
  long long ans = 1;
  if (suffix[1] != b[1]) {
    cout << 0 << endl;
  } else {
    for (i = 2; i <= m; i++) {
      ans = ans * cnt[b[i]] % mod;
    }
    cout << ans << endl;
  }
  return 0;
}
