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