#include <bits/stdc++.h>
using namespace std;
long long n, m, etot = 0;
long long head[100010], op[100010], dis[100010], v[100010], r[100010],
    ne[100010];
struct bi {
  long long x, y, l;
} b[300010];
bool cmp(bi t1, bi t2) { return t1.l < t2.l; }
struct pos {
  long long x, dis;
  bool friend operator<(pos t1, pos t2) { return t1.dis > t2.dis; }
};
priority_queue<pos> q;
struct ed {
  long long fr, to, nxt, l;
} e[300010];
void jb(long long x, long long y, long long z) {
  e[++etot] = {x, y, head[x], z};
  head[x] = etot;
}
inline long long read() {
  long long a = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + ch - '0';
  return a * f;
}
long long find(long long x) {
  if (r[x] == x) return x;
  return r[x] = find(r[x]);
}
void dij() {
  long long i, j, k;
  pos now;
  while (!q.empty()) {
    now = q.top();
    q.pop();
    i = now.x;
    if (dis[i] < now.dis) continue;
    for (j = head[i]; j; j = e[j].nxt) {
      k = e[j].to;
      if (dis[k] > dis[i] + e[j].l) {
        v[i] = 1;
        dis[k] = dis[i] + e[j].l;
        ne[k] = ne[i];
        q.push({k, dis[k]});
      }
    }
  }
}
signed main() {
  cin >> n >> m;
  long long i, j, k, ans = 1e9;
  while (m--) {
    i = read(), j = read(), k = read();
    jb(i, j, k);
    jb(j, i, k);
  }
  cin >> m;
  for (i = 1; i <= m; i++) {
    j = read();
    op[j] = 1;
  }
  memset(dis, 0x3f, sizeof dis);
  v[1] = 1, dis[1] = 0;
  q.push({1, 0});
  dij();
  for (i = 1; i <= n; i++) {
    if (op[i]) ans = min(ans, dis[i]);
  }
  memset(dis, 0x3f, sizeof dis);
  memset(v, 0, sizeof v);
  for (i = 1; i <= n; i++) {
    if (op[i]) {
      v[i] = 1;
      dis[i] = 0;
      ne[i] = i;
      q.push({i, 0});
    }
  }
  dij();
  for (i = 1; i <= n; i++) {
    r[i] = i;
  }
  for (i = 1; i <= etot; i++) {
    b[i] = {ne[e[i].fr], ne[e[i].to], e[i].l + dis[e[i].fr] + dis[e[i].to]};
  }
  sort(b + 1, b + etot + 1, cmp);
  long long cnt = 0;
  for (i = 1; i <= etot; i++) {
    j = find(b[i].x), k = find(b[i].y);
    if (j == k) continue;
    r[j] = k;
    cnt++;
    ans += b[i].l;
    if (cnt == n - 1) break;
  }
  cout << ans << endl;
  return 0;
}
