#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));
using namespace std;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
int main() {
  long long n, m;
  scanf("%lld %lld", &n, &m);
  vector<long long> a(n);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  vector<long long> b(m);
  for (int i = 0; i < m; i++) scanf("%lld", &b[i]);
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  vector<int> pos(m);
  {
    int cur = 0;
    for (int i = 0; i < n; i++) {
      if (cur == m) {
        if (a[i] < b.back()) {
          puts("0");
          return 0;
        }
      } else {
        if (a[i] == b[cur]) {
          pos[cur] = i;
          cur++;
        } else if (a[i] < b[cur]) {
          puts("0");
          return 0;
        }
      }
    }
    if (cur != m) {
      puts("0");
      return 0;
    }
  }
  long long left = 0;
  long long right = 0;
  mint res = 1;
  int cur = 0;
  for (int i = 0; i + 1 < m; i++) {
    for (int j = pos[i]; j < n; j++) {
      if (b[i] > a[j]) {
        res *= (j - pos[i]);
        break;
      }
    }
  }
  cout << res.x << "\n";
  return 0;
}
