#include <bits/stdc++.h>
using namespace std;
template <class t>
vector<t> sort(vector<t> &a) {
  return sort(a.begin(), a.end());
}
const int N = 200200;
int a[N], b[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  reverse(a, a + n);
  reverse(b, b + m);
  a[n] = -1;
  int pos = 0, mn = a[0];
  while (pos < n && mn > b[0]) pos++, mn = min(mn, a[pos]);
  if (pos == n || mn < b[0]) {
    puts("0");
    return 0;
  }
  assert(mn == b[0]);
  long long res = 1;
  for (int itr = 0; itr < m - 1; itr++) {
    bool f = 1;
    int npos = pos;
    while (npos < n && mn != b[itr + 1]) {
      npos++;
      mn = min(mn, a[npos]);
      if (f && mn < b[itr]) {
        f = 0;
        res = (res * (npos - pos)) % 998244353;
      }
    }
    if (npos == n || mn != b[itr + 1]) {
      puts("0");
      return 0;
    }
    pos = npos;
  }
  if (*min_element(a + pos, a + n) != b[m - 1]) {
    puts("0");
    return 0;
  }
  cout << res << '\n';
  return 0;
}
