#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  long long n, m, i, j, cnt, flg, ans, chk, ini, fin;
  cin >> n >> m;
  long long a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  chk = 0;
  flg = 0;
  long long b[m];
  long long fpos[m];
  long long ipos[m];
  for (i = 0; i < m; i++) {
    cin >> b[i];
    fpos[i] = -1;
    ipos[i] = -1;
  }
  j = m - 1;
  for (i = n - 1; i > -1 && j > -1; i--) {
    if (a[i] == b[j]) {
      if (ipos[j] == -1) ipos[j] = i;
    } else if (a[i] < b[j]) {
      if (ipos[j] == -1) {
        flg = 1;
        break;
      }
      if (j == 0) {
        flg = 1;
        break;
      }
      fpos[j] = i + 1;
      i++;
      j--;
      if (j < 0) break;
    }
  }
  for (i = 0; i < m; i++) {
    if (ipos[i] == -1) {
      flg = 1;
      break;
    }
  }
  fpos[0] = ipos[0];
  ans = 1;
  j = 0;
  i = 0;
  for (i = 0; i < m; i++) {
    ans = ((ans % mod) * ((ipos[i] - fpos[i] + 1) % mod)) % mod;
  }
  if (flg) {
    cout << 0;
  } else {
    cout << ans % mod;
  }
  cout << "\n";
}
