#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    unsigned n, m, x = 0;
    cin >> n >> m;
    unsigned b[m], a[n];
    for(int i = 0; i < m; i++)
        cin >> b[i];
    for(int i = 0; i < n; a[i++] = i);
    int c;
    cin >> c;
    for(int i = 0; i <= (n - m); i++)
        for(int j = 0; j < m; a[i + b[j] - 1] = a[i + j++]);
    for(int i = 0; i < n; x += (pow(c, i + 1) * a[i++]));
    cout << x;
    return 0;
}