#include <iostream>
#include <cmath>

using namespace std;

int main () {
	long M, N, c, B[100000], A[100000], X;
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> B[i];
	}
	for (int i = 1; i <= N; i++){
		A[i] = i;
	}
	for (int i = 0; i <= N - M; i++) {
		for (int j = 1; j <= M; j++) {
		A[i + B[j]] = A[i + j];
		}
	}
	cin >> c;
	for (int i = 1; i <= N; i++) {
		X = X + pow(c, i) * A[i];
	}
	cout << X;
	return 0;
}