#include <iostream>
using namespace std;

int main() {
    long int n, m, i, j, c, p, x;
    long int b[100000];
    long int a[20000000];
    cin >> n;
    cin >> m;
    for (i = 1; i <= m; i++) {
        cin >> b[i];
    }
    cin >> c;
    for (i = 1; i <= n; i++) {
        a[i] = i;
    }
    for (i = 0; i <= n - m; i++) {
        for (j = 1; j <= m; j++) {
            p = b[j];
            a[i + p] = a[i + j];
        }
    }
    x = 0;
    for (i = 1; i <= n; i++) {
        x = x + pow(c, i) * a[i];
    }
    cout << x << endl;
    return 0;
}