#include <bits/stdc++.h>
using namespace std;
struct aaa {
  long long x, y, w;
} a[200001];
long long n, m, k, tot, cnt, ans, sum, p[200001], fa[200001], dis[200001],
    mp[200001], val[200001], e[200001], hd[200001], nt[200001], fr[200001];
queue<long long> q;
void build(long long x, long long y, long long w) {
  tot++;
  fr[tot] = x;
  e[tot] = y;
  val[tot] = w;
  nt[tot] = hd[x];
  hd[x] = tot;
}
bool cmp(aaa a, aaa b) { return a.w < b.w; }
long long find(long long x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
int main() {
  long long i, x, y, w, u, v;
  scanf("%lld%lld", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%lld%lld%lld", &x, &y, &w);
    build(x, y, w);
    build(y, x, w);
  }
  scanf("%lld", &k);
  memset(dis, 44, sizeof(dis));
  for (i = 1; i <= k; i++) {
    scanf("%lld", &x);
    dis[x] = 0;
    p[x] = x;
    q.push(x);
    mp[x] = 1;
  }
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (i = hd[u]; i; i = nt[i]) {
      v = e[i];
      if (dis[v] > dis[u] + val[i]) {
        dis[v] = dis[u] + val[i];
        p[v] = p[u];
        if (!mp[v]) {
          mp[v] = 1;
          q.push(v);
        }
      }
    }
    mp[u] = 0;
  }
  for (i = 1; i <= n; i++) fa[i] = i;
  for (i = 1; i <= tot; i++) {
    u = fr[i];
    v = e[i];
    a[++cnt].x = p[u];
    a[cnt].y = p[v];
    a[cnt].w = dis[u] + dis[v] + val[i];
  }
  sort(a + 1, a + cnt + 1, cmp);
  sum = 1;
  ans = dis[1];
  for (i = 1; i <= cnt; i++) {
    x = a[i].x;
    y = a[i].y;
    if (x == y) continue;
    u = find(x);
    v = find(y);
    if (u != v) {
      fa[u] = v;
      ans += a[i].w;
      sum++;
    }
    if (sum >= k) break;
  }
  printf("%lld", ans);
}
