#include <stdio.h>
#include <cmath>

using namespace std;

int main()
{
    int N, M, C;
    scanf("%d %d",&N, &M);
    int B[M+1];
    for(int i = 1; i <= M; i++)
    {
        scanf("%d",&B[i]);
    }
    scanf("%d",&C);
    int A[N+1];
    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];
        }
    }
    int x = 0;
    for(int i = 1; i <= N; i++)
    {
        x+= pow(C,i)*A[i];
    }
    printf("%d",x);

    return 0;
}