#include <bits/stdc++.h>
using namespace std;
const int Max = 1e5 + 5;
const int Mod = 1e9 + 7;
int n, m, k;
vector<pair<int, long long>> G[Max];
int par[Max];
long long dis[Max];
int find(int u) {
  if (par[u] == u) return u;
  return par[u] = find(par[u]);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  while (m--) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }
  for (int i = 1; i <= n; i++) par[i] = i, dis[i] = -1;
  long long ans = 0;
  set<pair<long long, pair<int, int>>> q;
  cin >> k;
  bool ok = 0;
  while (k--) {
    int x;
    cin >> x;
    ok |= (x == 1);
    q.insert({0, {x, x}});
  }
  vector<pair<long long, pair<int, int>>> e;
  while (!q.empty()) {
    int u = q.begin()->second.first;
    int p = q.begin()->second.second;
    long long d = q.begin()->first;
    q.erase(q.begin());
    if (dis[u] != -1) continue;
    dis[u] = d;
    par[u] = p;
    for (auto v : G[u]) q.insert({d + v.second, {v.first, p}});
  }
  for (int i = 1; i <= n; i++)
    for (auto j : G[i]) {
      int v = j.first;
      int u = i;
      long long d = dis[u] + j.second + dis[v];
      u = find(u);
      v = find(v);
      if (v != u) e.push_back({d, {u, v}});
    }
  sort(e.begin(), e.end());
  for (auto i : e) {
    long long d = i.first;
    int u = i.second.first;
    int v = i.second.second;
    u = find(u);
    v = find(v);
    if (u != v) ans += d, par[u] = v;
  }
  if (!ok) ans += dis[1];
  cout << ans << endl;
  return 0;
}
