#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, MOD = 998244353;
int a[N], b[N], l[N], T[N], dp[N], ps[N] = {1}, val[N];
priority_queue<int> pq;
vector<int> Q[N];
int sum(int a, int b) { return a + b - (a + b >= MOD ? MOD : 0); }
int mul(int a, int b) { return 1ll * a * b % MOD; }
void update(int i, int x, int t) {
  ps[i] = sum(ps[i], mul((t - T[i]), dp[i]));
  dp[i] = x, T[i] = t;
  if (dp[i] > 0) pq.push(i);
  return;
}
int get(int i, int t) { return sum(ps[i], mul((t - T[i] + 1), dp[i])); }
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (cin >> a[i], l[i] = i - 1; l[i] && a[l[i]] >= a[i];) l[i] = l[l[i]];
    if (l[i]) Q[l[i] - 1].push_back(i);
  }
  for (int i = 1; i <= m; i++) cin >> b[i];
  for (int j : Q[0]) {
    int x = lower_bound(b + 1, b + m + 1, a[j]) - b;
    val[j] = get(x - 1, 0);
  }
  for (int i = 1; i <= n; i++) {
    int pos = lower_bound(b + 1, b + m + 1, a[i]) - b;
    if (b[pos] == a[i]) update(pos, sum(get(pos - 1, i - 1), MOD - val[i]), i);
    pos += (b[pos] == a[i]);
    while (!pq.empty() && pq.top() >= pos) update(pq.top(), 0, i), pq.pop();
    for (int j : Q[i]) {
      int x = lower_bound(b + 1, b + m + 1, a[j]) - b;
      val[j] = get(x - 1, i);
    }
  }
  cout << dp[m] << "\n";
}
