#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first) return a.second < b.second;
  return (a.first < b.first);
}
int main() {
  long long n, m, a[200010], b[200010];
  cin >> n >> m;
  vector<pair<long long, long long>> v;
  vector<pair<long long, long long>> c;
  c.push_back({0, 0});
  v.push_back({0, 0});
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    v.push_back({a[i], i});
  }
  for (long long i = 1; i <= m; i++) cin >> b[i];
  sort(v.begin(), v.end(), sortbysec);
  long long p = 1, f = 0;
  for (long long i = 1; i <= n;) {
    if (v[i].first < b[p]) {
      f = 0;
      i++;
      if (i == n + 1) break;
    }
    if (v[i].first > b[p]) {
      break;
      p = 0;
    }
    while (v[i].first == b[p]) {
      f = 1;
      i++;
      if (i == n + 1) break;
    }
    if (f == 1) {
      c.push_back({b[p], v[i - 1].second});
      p++;
      if (p > m) break;
      f = 0;
    }
  }
  if (p <= m) {
    cout << 0;
    return 0;
  }
  long long ans = 1, x, y;
  f = 0;
  for (long long i = 1; i < m; i++) {
    if (i == 1) {
      for (long long j = 1; j <= c[1].second; j++) {
        if (a[j] < c[1].first) {
          f = 1;
          ans = 0;
          break;
        }
      }
    }
    x = 0;
    for (long long j = c[i].second; j < c[i + 1].second; j++) {
      if (a[j] < c[i].first) {
        break;
      } else
        x++;
    }
    y = 0;
    for (long long j = c[i + 1].second; j > c[i].second; j--) {
      if (a[j] < c[i + 1].first) {
        break;
      } else
        y++;
    }
    long long u = x + c[i].second - 1;
    long long z = c[i + 1].second - y;
    if (u - z + 1 > 0)
      ans = (ans * (u - z + 1)) % mod;
    else {
      ans = 0;
      f = 1;
    }
    if (f == 1) {
      ans = 0;
      break;
    }
  }
  if (f == 1) {
    cout << 0;
    return 0;
  } else {
    for (long long j = c[m].second; j <= n; j++) {
      if (a[j] < c[m].first) {
        f = 1;
        ans = 0;
        break;
      }
    }
    if (f == 1) {
      cout << 0;
      return 0;
    } else
      cout << ans;
  }
}
