#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 998244353;
const long long inf = 1e18;
const double PI = acos(-1);
const double eps = 1e-8;
long long qkmod(long long base, long long cnt) {
  long long res = 1;
  while (cnt) {
    if (cnt & 1) res = res * base % mod;
    base = base * base % mod;
    cnt >>= 1;
  }
  return res;
}
int a[maxn], b[maxn], mi[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  mi[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) mi[i] = min(a[i], mi[i + 1]);
  long long ans = 1;
  int cnt = 0, j = 0;
  if (mi[0] < b[0]) return cout << 0, 0;
  for (int i = 0; i < m; i++) {
    if (j >= n || mi[j] > b[i]) return cout << 0, 0;
    cnt = 0;
    while (j < n && mi[j] <= b[i]) {
      if (mi[j] == b[i]) cnt++;
      j++;
    }
    if (i) ans = ans * cnt % mod;
  }
  cout << ans << endl;
}
