#include <bits/stdc++.h>
using namespace std;
const long long N = 100000 + 77;
long long n, m, k, par[N], P[N], T[N];
long long dis[N], A;
bool M[N], Pt[N];
vector<pair<long long, long long> > a[N];
vector<pair<long long, pair<long long, long long> > > V;
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    pq;
long long Find(long long v) { return P[v] == 0 ? v : (P[v] = Find(P[v])); }
void Merge(long long v, long long u, long long w) {
  v = Find(v);
  u = Find(u);
  if (v == u) {
    return;
  }
  A += w;
  P[u] = v;
}
int32_t main() {
  for (long long i = 0; i < N; i++) {
    dis[i] = 1e15;
  }
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    a[v].push_back(make_pair(u, w));
    a[u].push_back(make_pair(v, w));
  }
  cin >> k;
  for (long long i = 1; i <= k; i++) {
    cin >> T[i];
    Pt[T[i]] = 1;
    dis[T[i]] = 0;
    par[T[i]] = T[i];
  }
  sort(T + 1, T + 1 + k);
  for (long long i = 1; i <= k; i++) {
    pq.push(make_pair(0ll, T[i]));
  }
  while (!pq.empty()) {
    long long v = pq.top().second;
    pq.pop();
    if (M[v]) {
      continue;
    }
    M[v] = 1;
    for (auto x : a[v]) {
      long long u = x.first, w = x.second;
      if (dis[u] <= dis[v] + w) {
        continue;
      }
      par[u] = par[v];
      dis[u] = dis[v] + w;
      pq.push(make_pair(dis[u], u));
    }
  }
  A = dis[1];
  for (long long v = 1; v <= n; v++) {
    for (auto x : a[v]) {
      long long u = x.first, w = x.second;
      V.push_back(make_pair(dis[u] + dis[v] + w, make_pair(par[v], par[u])));
    }
  }
  sort(V.begin(), V.end());
  for (auto x : V) {
    long long v = x.second.first, u = x.second.second, w = x.first;
    if (!Pt[v] || !Pt[u]) {
      continue;
    }
    Merge(v, u, w);
  }
  cout << A;
  return 0;
}
