#include <bits/stdc++.h>
using namespace std;
int N, M;
int a[211000];
int b[211000];
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> b[i];
  }
  int i = N - 1;
  long long ans = 1;
  for (int j = M - 1; j >= 0; j--) {
    while (i >= 0 && a[i] != b[j]) {
      if (a[i] < b[j]) {
        cout << 0 << endl;
        return 0;
      }
      i--;
    }
    if (i < 0) {
      cout << 0 << endl;
      return 0;
    }
    long long cnt = 0;
    while (i >= 0 && a[i] >= b[j]) {
      cnt++;
      i--;
    }
    if (j == 0 && i >= 0)
      cnt = 0;
    else if (j == 0 && i < 0)
      cnt = 1;
    ans *= cnt;
    ans %= 998244353;
  }
  cout << ans << endl;
}
