#include <bits/stdc++.h>
using namespace std;
long long int par[100001], nearest_distance[100001], nearest_portal[100001],
    portal[100001];
vector<pair<long long int, pair<long long int, long long int> > > edge,
    new_edge;
vector<pair<long long int, long long int> > v[100001];
long long int find(long long int x) {
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int i, j, n, m, x, y, z, xp, yp, ans = 0, k, cur, nxt, cst, dis;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    v[x].push_back(make_pair(y, z));
    v[y].push_back(make_pair(x, z));
    edge.push_back(make_pair(z, make_pair(x, y)));
  }
  cin >> k;
  for (i = 1; i <= n; i++) nearest_distance[i] = 1000000000000000000;
  priority_queue<pair<long long int, long long int> > q;
  int add = 1;
  for (i = 1; i <= k; i++) {
    cin >> portal[i];
    if (portal[i] == 1) add = 0;
    nearest_portal[portal[i]] = portal[i];
    nearest_distance[portal[i]] = 0;
    q.push(make_pair(0, portal[i]));
  }
  while (!q.empty()) {
    cur = q.top().second;
    dis = -q.top().first;
    q.pop();
    if (nearest_distance[cur] != dis) continue;
    for (i = 0; i < v[cur].size(); i++) {
      nxt = v[cur][i].first;
      cst = v[cur][i].second;
      if (nearest_distance[nxt] > nearest_distance[cur] + cst) {
        nearest_distance[nxt] = nearest_distance[cur] + cst;
        nearest_portal[nxt] = nearest_portal[cur];
        q.push(make_pair(-nearest_distance[nxt], nxt));
      }
    }
  }
  for (i = 0; i < edge.size(); i++) {
    x = edge[i].second.first;
    y = edge[i].second.second;
    z = edge[i].first;
    new_edge.push_back(
        make_pair(z + nearest_distance[x] + nearest_distance[y],
                  make_pair(nearest_portal[x], nearest_portal[y])));
  }
  sort(new_edge.begin(), new_edge.end());
  for (i = 1; i <= n; i++) par[i] = i;
  for (i = 0; i < new_edge.size(); i++) {
    x = new_edge[i].second.first;
    y = new_edge[i].second.second;
    z = new_edge[i].first;
    xp = find(x);
    yp = find(y);
    if (xp == yp) continue;
    ans += z;
    par[xp] = yp;
  }
  if (add) ans += nearest_distance[1];
  cout << ans;
  return 0;
}
