#include <bits/stdc++.h>
using namespace std;
struct estado {
  int x;
  long long int cost;
  int cual;
};
priority_queue<estado> monti;
struct arista {
  int a;
  int b;
  long long int cost;
};
arista A[200002];
bool operator<(estado a, estado b) { return a.cost > b.cost; }
bool operator<(arista x, arista y) { return x.cost < y.cost; }
int n, m, k, pos;
long long int c;
long long int dist[200002];
int f[200002];
int nodo[200002], sig[200002];
long long int costo[200002];
int prim[200002], K[200002];
int p[200002];
bool interes[200002], vis[200002];
void agregaArista(int a, int b, long long int c) {
  nodo[++pos] = b;
  costo[pos] = c;
  sig[pos] = prim[a];
  prim[a] = pos;
}
void busqueda() {
  estado hijo, act;
  for (int i = 1; i <= k; i++) {
    hijo.x = K[i];
    hijo.cost = 0;
    hijo.cual = K[i];
    monti.push(hijo);
  }
  while (!monti.empty()) {
    act = monti.top();
    monti.pop();
    while (vis[act.x] && !monti.empty()) {
      act = monti.top();
      monti.pop();
    }
    if (vis[act.x]) return;
    vis[act.x] = true;
    dist[act.x] = act.cost;
    f[act.x] = act.cual;
    hijo.cual = act.cual;
    int posi = prim[act.x];
    while (posi) {
      hijo.x = nodo[posi];
      hijo.cost = costo[posi] + act.cost;
      if (!vis[hijo.x]) monti.push(hijo);
      posi = sig[posi];
    }
  }
}
bool func(arista x, arista y) { return x.cost < y.cost; }
struct lol {
  int a;
  int b;
};
lol hola[100002];
bool compara(lol q, lol p) { return q.a < q.b; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%I64d", &A[i].a, &A[i].b, &A[i].cost);
    agregaArista(A[i].a, A[i].b, A[i].cost);
    agregaArista(A[i].b, A[i].a, A[i].cost);
  }
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &K[i]);
    interes[K[i]] = true;
  }
  busqueda();
  for (int i = 1; i <= m; i++) {
    long long int nc;
    nc = dist[A[i].a] + A[i].cost + dist[A[i].b];
    A[i].a = f[A[i].a];
    A[i].b = f[A[i].b];
    A[i].cost = nc;
  }
  sort(A + 1, A + m + 1);
  int i = 1, j = 1, x, y, tx, ty;
  long long int resp = 0;
  for (int i = 1; i <= n; i++) p[i] = i;
  while (j < k) {
    x = A[i].a;
    y = A[i].b;
    tx = 0;
    ty = 0;
    while (p[x] != x) {
      x = p[x];
      tx++;
    }
    while (p[y] != y) {
      y = p[y];
      ty++;
    }
    if (x != y) {
      j++;
      resp += A[i].cost;
      if (tx > ty) {
        x = A[i].a;
        while (p[x] != x) {
          tx = p[x];
          p[x] = y;
          x = tx;
        }
        p[x] = y;
      } else {
        y = A[i].b;
        while (p[y] != y) {
          ty = p[y];
          p[y] = x;
          y = ty;
        }
        p[y] = x;
      }
    }
    i++;
  }
  if (!interes[1]) resp += dist[1];
  cout << resp << "\n";
  return 0;
}
