#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  long long mo = 998244353;
  cin >> n >> m;
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  vector<long long> arr2(m);
  for (int i = 0; i < m; i++) cin >> arr2[i];
  long long id = m - 1;
  long long t = 0;
  map<long long, long long> mp;
  long long mn = arr[n - 1];
  for (int i = n - 1; i >= 0; i--) {
    mn = min(mn, arr[i]);
    mp[mn]++;
  }
  if (mn != arr2[0]) {
    cout << 0;
    return;
  }
  long long ans = 1;
  for (long long i = 1; i < m; i++) {
    ans = (ans * mp[arr2[i]]) % mo;
  }
  cout << ans;
}
int main() {
  solve();
  return 0;
}
