#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long int maxn = 1001;
void solve() {
  long long int n, m;
  cin >> n >> m;
  long long int a[n], b[m];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long int i = 0; i < m; i++) cin >> b[i];
  long long int start[m], sk[m];
  long long int pos = m - 1;
  long long int f = 0;
  for (long long int i = n - 1; i >= 0 and pos >= 0; i--) {
    if (a[i] < b[pos]) {
      start[pos] = i + 1;
      pos--;
      i++;
      if (f == 0) break;
      f = 0;
    }
    if (f == 0 and a[i] == b[pos]) {
      f = 1;
      sk[pos] = i;
    }
    if (a[i] < b[0]) {
      f = 0;
      break;
    }
  }
  start[0] = 0;
  if (f == 0 or pos != 0)
    cout << 0 << endl;
  else {
    long long int ans = 1;
    for (long long int i = 1; i < m; i++) {
      ans *= (sk[i] - start[i] + 1);
      ans %= (long long int)(998244353);
    }
    cout << max(1LL * 0, ans) << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
