#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, long long int> > > G(n);
  int x, y, z;
  for (int i = 0; i < m; ++i) {
    cin >> x >> y >> z;
    G[x - 1].push_back(pair<int, long long int>(y - 1, z));
    G[y - 1].push_back(pair<int, long long int>(x - 1, z));
  }
  int k;
  cin >> k;
  vector<int> portals(k);
  for (int i = 0; i < k; ++i) {
    cin >> portals[i];
    portals[i]--;
  }
  map<int, int> portal_map;
  for (int i = 0; i < k; ++i) {
    portal_map[portals[i]] = i;
  }
  vector<long long int> cp(n, -1), dist(n, 100000000000);
  set<pair<long long int, int> > dijk;
  for (int i = 0; i < k; ++i) {
    cp[portals[i]] = portals[i];
    dist[portals[i]] = 0;
    dijk.insert(pair<long long int, int>(0, portals[i]));
  }
  while (!dijk.empty()) {
    pair<long long int, int> top = *dijk.begin();
    dijk.erase(dijk.begin());
    long long int d = top.first;
    int v = top.second;
    for (int i = 0; i < G[v].size(); ++i) {
      if (d + G[v][i].second < dist[G[v][i].first]) {
        if (dist[G[v][i].first] != 100000000000) {
          dijk.erase(dijk.find(
              pair<long long int, int>(dist[G[v][i].first], G[v][i].first)));
        }
        dist[G[v][i].first] = d + G[v][i].second;
        cp[G[v][i].first] = cp[v];
        dijk.insert(
            pair<long long int, int>(dist[G[v][i].first], G[v][i].first));
      }
    }
  }
  vector<vector<pair<int, long long int> > > portal_graph(k);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < G[i].size(); ++j) {
      if (cp[i] != cp[G[i][j].first]) {
        portal_graph[portal_map[cp[i]]].push_back(pair<int, long long int>(
            portal_map[cp[G[i][j].first]],
            dist[i] + G[i][j].second + dist[G[i][j].first]));
      }
    }
  }
  long long int fans = dist[0];
  vector<bool> visited(k, false);
  vector<long long int> prim_dist(k, 100000000000000000);
  dijk.insert(pair<long long int, int>(0, portal_map[cp[0]]));
  prim_dist[portal_map[cp[0]]] = 0;
  while (!dijk.empty()) {
    pair<long long int, int> top = *dijk.begin();
    dijk.erase(dijk.begin());
    fans += top.first;
    int v = top.second;
    visited[v] = true;
    for (int i = 0; i < portal_graph[v].size(); ++i) {
      if (!visited[portal_graph[v][i].first] &&
          portal_graph[v][i].second < prim_dist[portal_graph[v][i].first]) {
        if (prim_dist[portal_graph[v][i].first] != 100000000000000000) {
          dijk.erase(dijk.find(pair<long long int, int>(
              prim_dist[portal_graph[v][i].first], portal_graph[v][i].first)));
        }
        prim_dist[portal_graph[v][i].first] = portal_graph[v][i].second;
        dijk.insert(pair<long long int, int>(
            prim_dist[portal_graph[v][i].first], portal_graph[v][i].first));
      }
    }
  }
  cout << fans;
  return 0;
}
