#include <iostream>

using namespace std;

int main () {
	long M, N, c, B[100000], A[200000], X, power, t;
	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++) {
		power = 1;
		for (int l = 1; l <= i; l++) {
			power = power * c;
		}
		X = X + power * A[i];
	}
	cout << X-1;
	return 0;
}