#include <bits/stdc++.h>
using namespace std;
const long long N = 222222, mod = 998244353;
long long n, m, a[N], b[N];
void bad() {
  cout << 0;
  exit(0);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cout.precision(40);
  cin >> n >> m;
  if (m > n) bad();
  for (long long i = 0; i < n; ++i) cin >> a[i];
  for (long long i = 0; i < m; ++i) cin >> b[i];
  vector<pair<long long, long long>> vec(m);
  for (long long i = m - 1, j = n - 1; i >= 0; --i) {
    if (j < 0) bad();
    long long mn = a[j];
    while (j >= 0 && mn != b[i]) {
      j--;
      if (j >= 0) mn = min(a[j], mn);
    }
    if (j < 0) bad();
    vec[i].second = j;
    while (j >= 0 && a[j] >= mn) j--;
    vec[i].first = j + 1;
  }
  if (vec[0].first != 0) bad();
  long long res = 1;
  for (long long i = 1; i < m; ++i)
    res = res * (vec[i].second - vec[i].first + 1) % mod;
  cout << res;
}
