#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = (long long)(998244353)) {
  return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = (long long)(998244353)) {
  return (a % p + b % p) % p;
}
long long neg(long long a, long long p = (long long)(998244353)) {
  return (p - (a % p)) % p;
}
long long sub(long long a, long long b, long long p = (long long)(998244353)) {
  return add(a, neg(b));
}
long long fpow(long long x, long long y) {
  long long res = 1;
  x = x % (long long)(998244353);
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1LL) res = (res * x) % (long long)(998244353);
    y = y >> 1LL;
    x = (x * x) % (long long)(998244353);
  }
  return res;
}
long long inv(long long a, long long p = (long long)(998244353)) {
  return fpow(a, p - 2);
}
bool sa(const pair<long long, long long> &a,
        const pair<long long, long long> &b) {
  return (a.second < b.second);
}
bool fd(const pair<long long, long long> &a,
        const pair<long long, long long> &b) {
  return (a.first > b.first);
}
bool sd(const pair<long long, long long> &a,
        const pair<long long, long long> &b) {
  return (a.second > b.second);
}
long long dx[4] = {0, 0, 1, -1};
long long dy[4] = {1, -1, 0, 0};
bool valid(long long x, long long y, long long n, long long m) {
  if (x < 0 || y < 0) {
    return false;
  } else if (x >= n || y >= m) {
    return false;
  } else
    return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  T = 1;
  for (long long t = 1; t < T + 1; t++) {
    long long n, m, x, mini = LLONG_MAX, sz = 0, ind, ans;
    cin >> n >> m;
    long long a[n + 5], b[m + 5];
    vector<long long> v;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (long long i = 0; i < m; i++) {
      cin >> b[i];
    }
    x = m - 1;
    for (long long i = n - 1; i >= 0; i--) {
      mini = min(mini, a[i]);
      if (mini > b[x]) {
        if (sz >= 1) {
          sz++;
        }
      } else if (mini < b[x]) {
        mini = LLONG_MAX;
        i++;
        if (sz == 0) {
          cout << 0 << "\n";
          return 0;
        } else {
          x--;
          v.emplace_back(sz);
          sz = 0;
        }
      } else {
        sz++;
      }
      if (x == 0) {
        ind = i;
        break;
      }
    }
    mini = LLONG_MAX;
    for (long long i = 0; i < ind + 1; i++) {
      mini = min(mini, a[i]);
    }
    if (mini != b[0]) {
      cout << 0 << "\n";
      return 0;
    } else {
      ans = 1;
      for (long long i = 0; i < (long long)v.size(); i++) {
        ans = mult(ans, v[i]);
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
