#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mp;
int main() {
  ios_base::sync_with_stdio(false);
  long long int n, m, i, j, k;
  cin >> n >> m;
  long long int a[n + 5], b[m + 5];
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= m; i++) cin >> b[i];
  mp[a[n]]++;
  bool f = true;
  for (i = n - 1; i >= 1; i--) {
    a[i] = min(a[i], a[i + 1]);
    mp[a[i]]++;
    if (a[i] < b[1]) {
      f = false;
      break;
    }
  }
  if (mp[b[1]] == 0) f = false;
  if (f == false) {
    cout << 0 << endl;
    return 0;
  }
  long long int ans = 1;
  for (i = 2; i <= m; i++) {
    ans = ans * mp[b[i]];
    ans = ans % 998244353;
  }
  cout << ans << endl;
  return 0;
}
