#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long n, m, a[200010], b[201000], t[200100];
long long min(long long x, long long y) {
  if (x < y)
    return x;
  else
    return y;
}
long long max(long long x, long long y) {
  if (x < y)
    return y;
  else
    return x;
}
int main() {
  int summ = 0;
  for (int i = 1; i <= 100; i++) summ += i;
  int flag = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  int po;
  for (int i = 1; i <= n; i++)
    if (a[i] == b[1]) po = i;
  for (int i = n - 1; i >= 1; i--) a[i] = min(a[i], a[i + 1]);
  if (a[1] < b[1]) {
    cout << 0 << endl;
    flag = 1;
  }
  if (!flag) {
    int temp = m;
    for (int i = n; i >= 1; i--)
      if (b[temp] == a[i]) temp--;
    if (temp) {
      int summm = 0;
      for (int i = 1; i <= 100; i++) summm += i;
      cout << 0 << endl;
      return 0;
    } else {
      int summm = 0;
      for (int i = 1; i <= 100; i++) summm += i;
      long long temp = m;
      for (int i = n; i >= 1; i--) {
        if (b[temp] == a[i]) {
          t[temp] = 1;
          temp--;
          while (a[i - 1] == b[temp + 1]) {
            t[temp + 1]++;
            i--;
          }
        }
      }
      t[1] = max(t[1] - po, 1);
      long long ans = 1;
      for (int i = 1; i <= m; i++) ans = (ans * t[i]) % mod;
      cout << ans << endl;
    }
  }
  return 0;
}
