#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  int k = 0;
  long long ans = 1;
  for (int i = 0; i < m; i++) {
    bool o = false;
    int p = -1;
    for (int j = k; j < n; j++)
      if ((!o || i == m - 1) && a[j] < b[i]) {
        cout << 0 << "\n";
        return 0;
      } else if (a[j] == b[i] && !o) {
        o = true;
        p = j;
      } else if (o && a[j] < b[i]) {
        k = j;
        break;
      } else if (!o && j == n - 1) {
        cout << 0 << "\n";
        return 0;
      }
    if (p < 0) {
      cout << 0 << "\n";
      return 0;
    }
    if (i == m - 1)
      continue;
    else
      ans = (ans * (k - p)) % mod;
  }
  cout << ans << "\n";
}
