#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 998244353;
const char nl = '\n';
const int MX = 100001;
struct mi {
  long long v;
  explicit operator long long() const { return v; }
  mi() { v = 0; }
  mi(long long _v) {
    v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
    if (v < 0) v += MOD;
  }
  friend bool operator==(const mi& a, const mi& b) { return a.v == b.v; }
  friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
  friend bool operator<(const mi& a, const mi& b) { return a.v < b.v; }
  mi& operator+=(const mi& m) {
    if ((v += m.v) >= MOD) v -= MOD;
    return *this;
  }
  mi& operator-=(const mi& m) {
    if ((v -= m.v) < 0) v += MOD;
    return *this;
  }
  mi& operator*=(const mi& m) {
    v = v * m.v % MOD;
    return *this;
  }
  mi& operator/=(const mi& m) { return (*this) *= inv(m); }
  friend mi pow(mi a, long long p) {
    mi ans = 1;
    assert(p >= 0);
    for (; p; p /= 2, a *= a)
      if (p & 1) ans *= a;
    return ans;
  }
  friend mi inv(const mi& a) {
    assert(a.v != 0);
    return pow(a, MOD - 2);
  }
  mi operator-() const { return mi(-v); }
  mi& operator++() { return *this += 1; }
  mi& operator--() { return *this -= 1; }
  mi operator++(int) {
    mi temp;
    temp.v = v++;
    return temp;
  }
  mi operator--(int) {
    mi temp;
    temp.v = v--;
    return temp;
  }
  friend mi operator+(mi a, const mi& b) { return a += b; }
  friend mi operator-(mi a, const mi& b) { return a -= b; }
  friend mi operator*(mi a, const mi& b) { return a *= b; }
  friend mi operator/(mi a, const mi& b) { return a /= b; }
  friend ostream& operator<<(ostream& os, const mi& m) {
    os << m.v;
    return os;
  }
  friend istream& operator>>(istream& is, mi& m) {
    long long x;
    is >> x;
    m.v = x;
    return is;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < (N); i++) cin >> A[i];
  vector<int> B(M);
  for (int i = 0; i < (M); i++) cin >> B[i];
  map<int, set<int> > aVals;
  for (int i = 0; i < (N); i++) {
    aVals[A[i]].insert(i);
  }
  int nxt = 0;
  vector<pair<int, int> > as;
  for (int i = 0; i < (N); i++) as.push_back({A[i], i});
  sort(as.begin(), as.end());
  int L[M];
  int cur = -1;
  for (int i = 0; i < (N); i++) {
    while (nxt < M && B[nxt] <= as[i].first) {
      L[nxt] = cur;
      nxt++;
    }
    cur = max(cur, as[i].second);
  }
  mi ans = 1;
  for (int i = 0; i < (N); i++) {
    if (A[i] < B[0]) {
      cout << 0 << nl;
      return 0;
    }
  }
  for (int i = 0; i < (M); i++) {
    if ((int)(aVals[B[i]]).size() == 0) {
      ans = 0;
      continue;
    }
    if (i == 0) continue;
    mi cur = *(aVals[B[i]].rbegin());
    ans *= cur - L[i];
    if (cur < L[i]) {
      ans = 0;
    }
  }
  cout << ans << nl;
  return 0;
}
