#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const long long inf = 1e18;
vector<pair<long long, long long> > gfo[N];
long long dist[N];
vector<int> portals;
int comp[N];
void dijkstra(int n) {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  for (int i = int(0); i < int(n); ++i) dist[i] = inf;
  for (int u : portals) {
    pq.push({0, u});
    dist[u] = 0;
    comp[u] = u;
  }
  while (!pq.empty()) {
    pair<long long, long long> data = pq.top();
    pq.pop();
    long long d = data.first;
    int u = data.second;
    if (d > dist[u]) continue;
    for (pair<long long, long long> v : gfo[u]) {
      if (dist[u] + v.second < dist[v.first]) {
        dist[v.first] = dist[u] + v.second;
        pq.push({dist[v.first], v.first});
        comp[v.first] = comp[u];
      }
    }
  }
}
vector<pair<long long, pair<long long, long long> > > edges;
int p[N];
int find(int u) {
  if (p[u] == u) return p[u];
  return p[u] = find(p[u]);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = int(0); i < int(m); ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    gfo[u].push_back({v, w});
    gfo[v].push_back({u, w});
  }
  int k;
  cin >> k;
  portals.resize(k);
  for (int i = int(0); i < int(k); ++i) {
    cin >> portals[i];
    portals[i]--;
  }
  dijkstra(n);
  for (int u = int(0); u < int(n); ++u) {
    for (pair<long long, long long> v : gfo[u]) {
      if (comp[u] != comp[v.first]) {
        edges.push_back(
            {v.second + dist[u] + dist[v.first], {comp[v.first], comp[u]}});
      }
    }
    p[u] = u;
  }
  long long mst = dist[0];
  sort((edges).begin(), (edges).end());
  for (int i = int(0); i < int(int((edges).size())); ++i) {
    long long w = edges[i].first;
    int u = edges[i].second.first;
    int v = edges[i].second.second;
    if (find(u) != find(v)) {
      mst += w;
      p[p[u]] = p[v];
    }
  }
  cout << mst << endl;
  return 0;
}
