#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 2;
const long long M = 998244353;
const long long inf = 1e18 + 5;
int main() {
  int n;
  scanf("%d", &n);
  int m;
  scanf("%d", &m);
  int a[n];
  int b[m];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  int flag = 0;
  long long ans = 1;
  if (n < m)
    flag = 1;
  else {
    int pos = n - 1;
    for (int i = m - 1; i >= 0; i--) {
      int cur = b[i];
      int ct = 0;
      int from = n;
      while (pos >= 0) {
        if (a[pos] < cur) {
          break;
        }
        if (a[pos] == cur) {
          ct++;
          if (ct == 1) from = pos;
        }
        pos--;
      }
      if (from == n) flag = 1;
      if (i) ans = (ans * (from - pos)) % M;
    }
    if (pos >= 0) flag = 1;
  }
  if (flag)
    printf("%d\n", 0);
  else
    printf("%lld\n", ans);
  ;
}
