#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  int ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
inline int min(int x, int y, int z) { return min(x, min(y, z)); }
inline int max(int x, int y, int z) { return max(x, max(y, z)); }
inline int add(int x, int y) {
  return x + y >= 998244353 ? x + y - 998244353 : x + y;
}
inline int add(int x, int y, int z) { return add(add(x, y), z); }
inline int sub(int x, int y) { return x - y < 0 ? x - y + 998244353 : x - y; }
inline int mul(int x, int y) { return 1LL * x * y % 998244353; }
inline int mul(int x, int y, int z) { return mul(mul(x, y), z); }
int f[200005], a[200005], b[200005];
map<int, int> c;
signed main() {
  int n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= m; i++) b[i] = read();
  f[m + 1] = 1;
  for (int i = 1; i <= m; i++) c[b[i]] = i;
  int cur = 0x3f3f3f3f;
  for (int i = n; i >= 1; i--) {
    cur = min(cur, a[i]);
    if (c[cur]) f[c[cur]] = add(f[c[cur]], f[c[cur] + 1]);
  }
  if (cur != b[1])
    cout << 0 << endl;
  else
    cout << f[2] << endl;
  return 0;
}
