#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 2e9, MOD = 998244353;
int32_t main() {
  ios_base::sync_with_stdio(false);
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> a(n), b(m);
  for (int64_t i = 0; i < n; i++) cin >> a[i];
  for (int64_t j = 0; j < m; j++) cin >> b[j];
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  int64_t i = 0, ans = 1;
  for (int64_t j = 0; j < m; j++) {
    int64_t first = -1;
    while (i < n && a[i] >= b[j]) {
      if (a[i] == b[j] && first == -1) first = i;
      i++;
    }
    if (first == -1)
      ans = 0;
    else {
      if (j == m - 1) continue;
      ans = ans * (i - first) % MOD;
    }
  }
  if (i != n) ans = 0;
  cout << ans << endl;
  return 0;
}
