#include <bits/stdc++.h>
using namespace std;
const long long N = 2 * 1e5 + 100;
long long n, m, k, w, a[N], d[N], p[N], fa[N], vi[N];
long long tot, first[N], nxt[N * 2], point[N * 2], len[N * 2];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    q;
struct node {
  long long u, v, w;
} sh[N];
bool cmp(node a, node b) { return a.w < b.w; }
long long find(long long x) {
  return (x == fa[x]) ? fa[x] : fa[x] = find(fa[x]);
}
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
inline void add_edge(long long x, long long y, long long z) {
  nxt[++tot] = first[x];
  first[x] = tot;
  point[tot] = y;
  len[tot] = z;
}
inline bool merge(long long a, long long b) {
  long long fax = find(a), fay = find(b);
  if (fax == fay) return 0;
  fa[fax] = fay;
  return 1;
}
signed main() {
  tot = -1;
  memset(first, -1, sizeof(first));
  n = read();
  m = read();
  for (long long i = 1; i <= m; i++) {
    long long u = read(), v = read(), w = read();
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  k = read();
  for (long long i = 1; i <= k; i++) a[i] = read();
  for (long long i = 1; i <= n; i++) d[i] = 1e18;
  for (long long i = 1; i <= k; i++)
    p[a[i]] = a[i], d[a[i]] = 0, q.push(make_pair(0, a[i]));
  while (!q.empty()) {
    long long x = q.top().second;
    q.pop();
    if (vi[x]) continue;
    vi[x] = 1;
    for (long long i = first[x]; i != -1; i = nxt[i]) {
      long long u = point[i];
      if (d[u] > d[x] + len[i]) {
        d[u] = d[x] + len[i];
        p[u] = p[x];
        q.push(make_pair(d[u], u));
      }
    }
  }
  for (long long i = 0; i <= tot; i += 2) {
    long long u = point[i], v = point[i ^ 1];
    if (p[u] == p[v]) continue;
    sh[++w] = (node){p[u], p[v], d[u] + d[v] + len[i]};
  }
  sort(sh + 1, sh + 1 + w, cmp);
  for (long long i = 1; i <= n; i++) fa[i] = i;
  long long ans = d[1];
  for (long long i = 1; i <= w; i++)
    if (merge(sh[i].u, sh[i].v)) ans += sh[i].w;
  printf("%lld\n", ans);
}
