#include <bits/stdc++.h>   using namespace std;   long long mod, n, m, a[200005], b[200005], kq, vt1, vt2, l, r, mid, mn[200005];   map<int, bool> mp;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     mod = 998244353;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       mp[a[i]] = true;     }     for (int i = 1; i <= m; ++i) {       cin >> b[i];       if (!mp[b[i]]) {         cout << 0;         return 0;       }     }     for (int i = 1; i <= n; ++i) {       if (a[i] < b[1]) {         cout << 0;         return 0;       }       if (a[i] == b[m]) vt1 = i;     }     for (int i = n; i > vt1; --i)       if (a[i] < b[m]) {         cout << 0;         return 0;       }     mn[n] = a[n];     for (int i = n - 1; i > 0; --i) mn[i] = min(a[i], mn[i + 1]);     kq = 1;     for (int i = 1; i < m; ++i) {       l = 1;       r = n - 1;       while (l <= r) {         mid = (l + r) / 2;         if (mn[mid + 1] >= b[i + 1]) {           vt1 = mid;           r = mid - 1;         } else           l = mid + 1;       }       l = 1;       r = n - 1;       while (l <= r) {         mid = (l + r) / 2;         if (mn[mid + 1] > b[i + 1])           r = mid - 1;         else {           vt2 = mid;           l = mid + 1;         }       }       kq = kq * max(0LL, vt2 - vt1 + 1) % mod;       ;     }     cout << kq;     return 0;   }   