#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18 + 5;
const int MOD = (int)1e9 + 7;
const int LOG = 20;
const int INF = 1e9;
const int N = 1e5 + 5;
const int M = 350;
const int SQ = 350;
struct node {
  int x;
  long long int cost;
  int from;
};
bool operator<(node a, node b) { return a.cost > b.cost; }
priority_queue<node> Q;
vector<pair<long long int, pair<int, int>>> v;
vector<pair<int, int>> ed[N];
int n, m, k, from[N], dad[N], port[N];
long long int ans, dist[N];
int find(int x) { return dad[x] = x == dad[x] ? x : find(dad[x]); }
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    ed[u].push_back(make_pair(v, c));
    ed[v].push_back(make_pair(u, c));
  }
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    int u;
    scanf("%d", &u);
    Q.push({u, 0, u});
    port[u] = 1;
  }
  memset(dist, -1, sizeof dist);
  while ((int)Q.size()) {
    auto temp = Q.top();
    Q.pop();
    if (dist[temp.x] != -1) continue;
    dist[temp.x] = temp.cost;
    from[temp.x] = temp.from;
    for (auto i : ed[temp.x])
      Q.push({i.first, temp.cost + i.second, temp.from});
  }
  for (int i = 1; i <= n; i++) {
    for (auto j : ed[i])
      if (from[j.first] != from[i])
        v.push_back(make_pair(dist[i] + dist[j.first] + j.second,
                              make_pair(from[i], from[j.first])));
    dad[i] = i;
  }
  sort(v.begin(), v.end());
  for (auto i : v) {
    int dx = find(i.second.second);
    int dy = find(i.second.first);
    if (dx != dy) {
      dad[dy] = dx;
      ans += i.first;
    }
  }
  printf("%lld\n", ans + dist[1]);
  return 0;
}
