#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  long long a[n], b[m];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  map<long long, long long> make_pair;
  for (long long i = n - 1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
  for (long long i = 0; i < n; i++) make_pair[a[i]]++;
  long long flag = 1;
  for (long long i = 0; i < m; i++)
    if (make_pair[b[i]] == 0) flag = 0;
  if (b[0] > a[0]) flag = 0;
  if (!flag) {
    cout << flag;
    return 0;
  }
  long long ans = 1;
  for (long long i = 1; i < m; i++) ans = ans * make_pair[b[i]] % 998244353;
  cout << ans;
  return 0;
}
