#include <bits/stdc++.h>
using namespace std;
long long int add(long long int x, long long int y) {
  return (x % 1000000007 + y % 1000000007) % 1000000007;
}
long long int mul(long long int x, long long int y) {
  return ((x % 1000000007) * (y % 1000000007)) % 1000000007;
}
long long int sub(long long int x, long long int y) {
  return (x - y + 1000000007) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  for (int ok = 1; ok <= t; ok++) {
    long long int n, m;
    cin >> n >> m;
    long long int a[n + 2], b[m + 3], c[n + 3];
    map<long long int, long long int> lol, hol;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= m; i++) {
      cin >> b[i];
    }
    c[n] = a[n];
    for (int i = n - 1; i >= 1; i--) {
      c[i] = min(a[i], c[i + 1]);
    }
    for (int i = 1; i <= n; i++) {
      if (lol.count(c[i]) == 0)
        lol[c[i]] = i;
      else
        continue;
    }
    for (int i = n; i >= 1; i--) {
      if (hol.count(c[i]) == 0)
        hol[c[i]] = i;
      else
        continue;
    }
    std::vector<pair<long long int, long long int>> v, u;
    v.push_back({0, 0});
    long long int w = 0;
    for (int i = 1; i <= m; i++) {
      long long int x = lol[b[i]];
      long long int y = hol[b[i]];
      v.push_back({x, y});
      if (x == 0 || y == 0) {
        cout << 0;
        return 0;
      }
    }
    if (v[1].first != 1) {
      cout << 0;
      return 0;
    }
    long long int ans = 1;
    for (int i = 2; i <= m; i++) {
      ans = (ans * (v[i].second - v[i].first + 1)) % 998244353;
    }
    cout << ans << '\n';
  }
  return 0;
}
