#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int T;
  {
    long long int t, n, i, j, x, y, m, l, d, k;
    cin >> n >> m;
    vector<long long int> a(n);
    for (i = 0; i < (n); ++i) cin >> a[i];
    vector<long long int> b(m);
    for (i = 0; i < (m); ++i) cin >> b[i];
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    long long int ans = 1;
    j = 0;
    long long int curr = 0;
    long long int chkr = b[0];
    long long int fst = -1;
    for (i = 0; i < (n); ++i) {
      if (a[i] == chkr) {
        if (fst == -1) curr = 0;
        if (fst == -1) fst = i;
        curr++;
        continue;
      }
      if (a[i] > chkr) {
        curr++;
        continue;
      }
      if (fst == -1) {
        cout << 0 << "\n";
        return 0;
      }
      ans *= (curr);
      ans %= 998244353;
      ans += 998244353;
      ans %= 998244353;
      j++;
      curr = 0;
      fst = -1;
      i--;
      if (j == m) {
        cout << 0 << "\n";
        return 0;
      } else {
        chkr = b[j];
      }
    }
    if (fst == -1) ans = 0;
    if (j == (m - 1))
      cout << ans << "\n";
    else
      cout << 0 << "\n";
  }
}
