#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(15) << fixed;
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  set<int> minims;
  minims.insert(a[n - 1]);
  int pet = a[n - 1];
  map<int, int> ml, mr;
  ml[a[n - 1]] = mr[a[n - 1]] = n - 1;
  for (int j = n - 1; j >= 0; j--) {
    if (a[j] >= pet)
      ml[pet] = j;
    else {
      pet = a[j];
      minims.insert(pet);
      ml[pet] = mr[pet] = j;
    }
  }
  vector<int> b(m);
  ll sol = 1;
  const ll mod = 998244353;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    if (i == 0 and b[0] != *minims.begin()) {
      cout << 0 << endl;
      return 0;
    }
    if (minims.find(b[i]) == minims.end()) {
      cout << 0 << endl;
      return 0;
    }
    if (i > 0) {
      sol = sol * (mr[b[i]] - max(mr[b[i - 1]], ml[b[i]] - 1)) % mod;
    }
  }
  cout << sol << endl;
}
