#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long double PI = acosl(-1);
const long long infl = 1e18;
const int inf = 2e9;
const int nmax = 4e5 + 5;
const int MAXLG = log2(nmax) + 1;
void NA() { cout << "0", exit(0); }
int a[nmax], b[nmax];
int pos[nmax], prefpos[nmax];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  if (n < m) NA();
  vector<int> shob;
  for (int i = 1; i <= n; i++) cin >> a[i], shob.push_back(a[i]);
  for (int i = 1; i <= m; i++) cin >> b[i], shob.push_back(b[i]);
  sort(shob.begin(), shob.end());
  shob.erase(unique(shob.begin(), shob.end()), shob.end());
  for (int i = 1; i <= n; i++)
    a[i] = upper_bound(shob.begin(), shob.end(), a[i]) - shob.begin();
  for (int i = 1; i <= m; i++)
    b[i] = upper_bound(shob.begin(), shob.end(), b[i]) - shob.begin();
  for (int i = 1; i <= n; i++) pos[a[i]] = i;
  for (int i = 1; i <= m; i++) {
    if (pos[b[i]] == 0) NA();
  }
  for (int i = 1; i < b[1]; i++)
    if (pos[i]) NA();
  for (int i = 1; i <= n; i++) prefpos[i] = max(prefpos[i - 1], pos[i]);
  long long ans = 1;
  for (int i = 2; i <= m; i++) {
    int p1 = prefpos[b[i] - 1];
    int p2 = pos[b[i]];
    if (p2 <= p1) NA();
    ans = (ans * 1LL * (p2 - p1)) % mod;
  }
  cout << ans << endl;
}
