#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010];
const long long mod = 998244353;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  a[n + 1] = 0x3f3f3f3f;
  for (int i = n; i >= 1; i--) {
    a[i] = min(a[i], a[i + 1]);
  }
  if (a[1] != b[1]) {
    cout << 0 << endl;
  } else {
    long long ans = 1;
    for (int i = 2; i <= m; i++) {
      long long tmp = upper_bound(a + 1, a + n + 1, b[i]) -
                      lower_bound(a + 1, a + 1 + n, b[i]);
      ans = ans * tmp % mod;
    }
    cout << ans << endl;
  }
  return 0;
}
