#include <bits/stdc++.h>
using namespace std;
const long long int MAXN = 2e5 + 10;
const long long int INF = 8e18;
long long int n, m, k, port[MAXN], dist[MAXN], par[MAXN], sz[MAXN], comp[MAXN],
    cost, mark[MAXN];
vector<pair<long long int, long long int>> adj[MAXN];
vector<pair<long long int, pair<long long int, long long int>>> E;
int Find(int u) { return (par[u] == -1 ? u : par[u] = Find(par[u])); }
bool Union(int u, int v) {
  int pu = Find(u), pv = Find(v);
  if (pu == pv) return false;
  if (sz[pu] < sz[pv]) swap(pu, pv);
  par[pv] = pu;
  sz[pu] += sz[pv];
  return true;
}
void dijk() {
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      pq;
  fill(dist, dist + MAXN, INF);
  for (int i = 0; i < k; i++) {
    pq.push({0, port[i]});
    dist[port[i]] = 0;
    comp[port[i]] = i + 1;
  }
  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();
    if (mark[u]) continue;
    mark[u] = 1;
    for (pair<long long int, long long int>& e : adj[u]) {
      int v = e.first, w = e.second;
      if (dist[v] <= dist[u] + w) {
        E.push_back({dist[u] + dist[v] + w, {comp[u], comp[v]}});
        continue;
      }
      dist[v] = dist[u] + w;
      comp[v] = comp[u];
      pq.push({dist[v], v});
    }
  }
}
int main() {
  fill(par, par + MAXN, -1);
  fill(sz, sz + MAXN, 1);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].emplace_back(v, w);
    adj[v].emplace_back(u, w);
  }
  cin >> k;
  for (int i = 0; i < k; i++) cin >> port[i];
  dijk();
  sort(E.begin(), E.end());
  for (auto e : E) {
    int u = e.second.first, v = e.second.second;
    if (Union(u, v)) cost += e.first;
  }
  cout << cost + dist[1] << '\n';
}
