#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 30, Mod = 1e9 + 7;
const long long SQ = 330;
vector<pair<long long, long long> > G[N];
long long n, m, k, par[N], P[N];
vector<long long> first[N], vec;
long long d[N];
struct Edge {
  long long v, u, w;
} E[N];
long long Get(long long v) { return P[v] ^ v ? P[v] = Get(P[v]) : v; }
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  iota(P, P + N, 0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    E[i] = {v, u, w};
    G[v].push_back({u, w});
    G[u].push_back({v, w});
  }
  memset(d, 63, sizeof d);
  cin >> k;
  for (int i = 0; i < k; i++) {
    long long x;
    cin >> x;
    d[x] = 0;
    par[x] = x;
  }
  set<pair<long long, long long> > D;
  for (int i = 1; i <= n; i++) {
    D.insert({d[i], i});
  }
  while (D.size()) {
    auto X = *D.begin();
    long long v = X.second;
    D.erase(X);
    for (auto K : G[v]) {
      long long u = K.first, w = K.second;
      if (d[u] > d[v] + w) {
        D.erase({d[u], u});
        d[u] = d[v] + w;
        par[u] = par[v];
        D.insert({d[u], u});
      }
    }
  }
  vector<pair<long long, pair<long long, long long> > > Ed;
  for (int i = 1; i <= m; i++) {
    long long v = E[i].v, u = E[i].u, w = E[i].w;
    long long vv, uu;
    vv = par[v];
    uu = par[u];
    if (vv == uu) continue;
    Ed.push_back({w + d[v] + d[u], {vv, uu}});
  }
  long long ans = d[1];
  sort(Ed.begin(), Ed.end());
  for (auto X : Ed) {
    long long v = X.second.first, u = X.second.second;
    v = Get(v);
    u = Get(u);
    if (v == u) continue;
    ans += X.first;
    P[v] = u;
  }
  cout << ans;
}
