#include <bits/stdc++.h>
using namespace std;
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const long long MAXN = 1e6 + 10;
const long long INF = 8e18;
const long long MOD = 1e9 + 7;
int n, m, k, src[MAXN], par[MAXN], H[MAXN];
vector<pair<long long, long long>> adj[MAXN];
vector<pair<long long, pair<long long, long long>>> mst_edges;
long long dist[MAXN], ans;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
               greater<pair<long long, long long>>>
    pq;
inline void Dijkstra() {
  while (!pq.empty()) {
    long long v = pq.top().second, d_v = pq.top().first;
    pq.pop();
    if (d_v != dist[v]) continue;
    for (pair<long long, long long> e : adj[v]) {
      long long t_d = d_v + e.second, u = e.first;
      if (dist[u] > t_d) {
        dist[u] = t_d;
        src[u] = src[v];
        pq.push({t_d, u});
      }
    }
  }
}
inline void make_source(int v) {
  if (dist[v] == 0) return;
  dist[v] = 0;
  pq.push({0, v});
  src[v] = v;
  par[v] = v;
}
int Find(int v) {
  if (v == par[v]) return v;
  return par[v] = Find(par[v]);
}
inline void Union(int v, int u) {
  v = Find(v);
  u = Find(u);
  if (v == u) return;
  if (H[v] > H[u]) swap(v, u);
  par[v] = u;
  if (H[v] == H[u]) H[u]++;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  fill(dist, dist + MAXN, INF);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  cin >> k;
  vector<int> vec;
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    vec.push_back(x);
    make_source(x);
  }
  Dijkstra();
  for (int v = 1; v <= n; v++) {
    for (pair<long long, long long> e : adj[v]) {
      int u = e.first;
      if (src[u] != src[v]) {
        mst_edges.push_back({dist[u] + dist[v] + e.second, {src[u], src[v]}});
      }
    }
  }
  sort((mst_edges).begin(), (mst_edges).end());
  for (auto e : mst_edges) {
    if (Find(e.second.first) != Find(e.second.second)) {
      ans += e.first;
      Union(e.second.first, e.second.second);
    }
  }
  fill(dist, dist + MAXN, INF);
  while (!pq.empty()) pq.pop();
  make_source(1);
  Dijkstra();
  long long mn_dist = INF;
  for (int e : vec) mn_dist = min(mn_dist, dist[e]);
  cout << ans + mn_dist << '\n';
  return 0;
}
