#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9 + 1;
const int Mod = 998244353;
void add_self(int& x, int y) {
  if ((x += y) >= Mod) x -= Mod;
}
int add(int x, int y) { return add_self(x, y), x; }
int sub_self(int& x, int y) {
  if ((x -= y) < 0) x += Mod;
}
int sub(int x, int y) { return sub_self(x, y), x; }
int mul(int x, int y) { return (long long)x * y % Mod; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int& x : a) scanf("%d", &x);
  vector<int> b(m);
  for (int& x : b) scanf("%d", &x);
  vector<int> SuffMin(n + 1, Inf);
  for (int i = n - 1; ~i; --i) SuffMin[i] = min(a[i], SuffMin[i + 1]);
  vector<int> Dp(n + 1);
  vector<int> SuffDp(n + 2);
  Dp[n] = SuffDp[n] = 1;
  for (int i = n - 1; ~i; --i) {
    int x = SuffMin[i];
    int j = lower_bound(b.begin(), b.end(), x) - b.begin();
    if (j < m && x == b[j]) {
      if (j == m - 1) {
        Dp[i] = 1;
      } else {
        int L = -1;
        int LowL = i + 1, HighL = n;
        while (LowL <= HighL) {
          int MidL = LowL + (HighL - LowL) / 2;
          if (SuffMin[MidL] >= b[j + 1]) {
            L = MidL;
            HighL = MidL - 1;
          } else {
            LowL = MidL + 1;
          }
        }
        int R = -1;
        int LowR = i + 1, HighR = n;
        while (LowR <= HighR) {
          int MidR = LowR + (HighR - LowR) / 2;
          if (SuffMin[MidR] > b[j + 1]) {
            R = MidR;
            HighR = MidR - 1;
          } else {
            LowR = MidR + 1;
          }
        }
        Dp[i] = sub(SuffDp[L], SuffDp[R]);
      }
    }
    SuffDp[i] = add(Dp[i], SuffDp[i + 1]);
  }
  int Ans = 0;
  if (SuffMin[0] == b[0]) Ans = Dp[0];
  cout << Ans << endl;
}
