#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
struct edge {
  int u, v;
  ll w;
  edge(int u, int v, ll w) : u(u), v(v), w(w) {}
};
int n, m, k, closestP[N], par[N];
ll d[N], res;
bool is1portal;
vector<int> portal;
vector<edge> adj[N], edges;
int root(int v) { return (par[v] < 0) ? v : (par[v] = root(par[v])); }
void join(int x, int y) {
  if ((x = root(x)) == (y = root(y))) return;
  if (par[x] > par[y]) swap(x, y);
  par[x] += par[y];
  par[y] = x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].emplace_back(u, v, w);
    adj[v].emplace_back(v, u, w);
  }
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    int p;
    cin >> p;
    portal.emplace_back(p);
    if (p == 1) is1portal = true;
  }
  priority_queue<pair<ll, pair<int, int>>> q;
  for (int i = 1; i <= n; ++i) d[i] = 1e18;
  for (int p : portal) q.push({d[p] = 0, {p, p}});
  while (!q.empty()) {
    int u = q.top().second.first;
    int p = q.top().second.second;
    q.pop();
    if (closestP[u]) continue;
    closestP[u] = p;
    for (edge e : adj[u]) {
      if (d[e.v] > d[u] + e.w) {
        d[e.v] = d[u] + e.w;
        q.push({-d[e.v], {e.v, p}});
      }
    }
  }
  for (int u = 1; u <= n; ++u) {
    for (edge e : adj[u]) {
      edges.emplace_back(closestP[u], closestP[e.v], d[u] + d[e.v] + e.w);
    }
  }
  sort(edges.begin(), edges.end(),
       [](const edge &x, const edge &y) { return x.w < y.w; });
  for (int i = 1; i <= n; ++i) par[i] = -1;
  for (edge e : edges) {
    if (root(e.u) != root(e.v)) {
      join(e.u, e.v);
      res += e.w;
    }
  }
  if (!is1portal) res += d[1];
  cout << res;
  return 0;
}
