#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long n, m, k;
vector<pair<long long, long long> > ad[N];
bool pt[N];
long long par[N];
long long dis[N];
void djk() {
  set<pair<pair<long long, long long>, long long> > s;
  for (long long i = 1; i <= n; i++)
    if (pt[i]) s.insert({{1, i}, i});
  while (s.size()) {
    long long v = s.begin()->first.second;
    long long d = s.begin()->first.first;
    long long p = s.begin()->second;
    s.erase(s.begin());
    if (par[v]) continue;
    par[v] = p;
    dis[v] = d;
    for (auto pi : ad[v]) s.insert({{d + pi.second, pi.first}, p});
  }
}
long long res;
long long pr[N];
long long findpar(long long v) {
  if (v == pr[v]) return v;
  return pr[v] = findpar(pr[v]);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    ad[v].push_back({u, w});
    ad[u].push_back({v, w});
  }
  cin >> k;
  for (long long i = 1; i <= k; i++) {
    long long t;
    cin >> t;
    pr[t] = t;
    pt[t] = 1;
  }
  djk();
  res += dis[1] - 1;
  set<pair<long long, pair<long long, long long> > > s;
  for (long long v = 1; v <= n; v++) {
    dis[v]--;
    for (auto p : ad[v]) {
      long long u = p.first;
      long long w = p.second;
      s.insert({dis[v] + dis[u] + w, {par[v], par[u]}});
    }
  }
  while (s.size()) {
    long long d = s.begin()->first;
    long long v = findpar(s.begin()->second.first);
    long long u = findpar(s.begin()->second.second);
    s.erase(s.begin());
    if (v == u) continue;
    res += d;
    pr[v] = u;
  }
  cout << res;
  return 0;
}
