#include using namespace std; template vector z_algorithm(const T &s) { int n = s.size(); vector res(n, 0); for(int i = 1, j = 0; i < n; ++i){ if(i + res[i - j] < j + res[j]){ res[i] = res[i - j]; }else{ res[i] = max(j + res[j] - i, 0); while(i + res[i] < n && s[i + res[i]] == s[res[i]]) ++res[i]; j = i; } } res[0] = n; return res; } const long long INF = 1LL << 60; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector a(n), b(m); vector c(m); for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 0; i < m; i++){ cin >> b[i]; } for(int i = 0; i < m; i++){ cin >> c[i]; } vector d(n + m); for(int i = 0; i < n; i++){ d[i] = a[i]; } for(int i = 0; i < m; i++){ d[i + n] = b[i]; } vector z = z_algorithm(d); vector dp(m + 1, INF); dp[0] = 0; for(int i = 0; i < m; i++){ int add = min(n, z[i + n]); for(int j = i + 1; j < i + add + 1; j++){ dp[j] = min(dp[j], dp[i] + c[i] * (j - i)); } } if(dp[m] == INF){ cout << -1 << endl; }else{ cout << dp[m] << endl; } }