#include <bits/stdc++.h>
using namespace std;
long long a[200002], b[200002], n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  long long ans = 1, k = m, l = n + 1, f = 1;
  b[m + 1] = 10000000000001;
  for (int i = n; i >= 1; i--) {
    if (k == 0) {
      if (a[i] < b[1]) {
        ans = 0;
        break;
      }
      continue;
    }
    if (a[i] < b[k]) {
      ans = 0;
      break;
    } else if (a[i] < b[k + 1] && f) {
      ans = ans * (l - i) % 998244353;
      f = 0;
    }
    if (a[i] == b[k]) {
      f = 1;
      l = i;
      k--;
    }
  }
  if (k > 0) ans = 0;
  cout << ans;
  return 0;
}
