#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1001, MOD = 998244353;
int n, m, a[N], b[N], res = 1;
int _mul(int a, int b) { return 1LL * a * b % MOD; }
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 index = n - 1;
  for (int i = m - 1; 0 <= i; i--) {
    int cnt = 0;
    while (a[index] > b[i] && index >= 0) index--;
    if (index < 0 || a[index] != b[i]) {
      cout << "0\n";
      return 0;
    }
    while (a[index] >= b[i] && index >= 0) {
      index--;
      cnt++;
    }
    res = (i ? _mul(res, cnt) : res);
  }
  if (index < 0)
    cout << res << "\n";
  else
    cout << "0\n";
}
