#include <bits/stdc++.h>
using namespace std;
const int maxn = 400005;
const long long INFll = 1000000000000000000ll;
struct edge {
  int from, to, next;
  long long w;
} e[maxn];
int head[maxn], cnte;
void add(int u, int v, long long w) {
  e[++cnte].from = u, e[cnte].to = v, e[cnte].w = w, e[cnte].next = head[u],
  head[u] = cnte;
}
struct T {
  int u, v;
  long long w;
  bool operator<(const T &x) const { return w < x.w; }
} t[maxn];
int n, m, k, vis[maxn], f[maxn], p[maxn];
long long dis[maxn];
void dijkstra(int start) {
  for (int i = 1; i <= n + 1; i++) dis[i] = INFll, vis[i] = 0;
  dis[start] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  q.push(pair<long long, int>(0, start));
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (dis[u] + e[i].w < dis[v] && !vis[v]) {
        dis[v] = dis[u] + e[i].w;
        q.push(pair<long long, int>(dis[v], v));
        if (u == n + 1)
          p[v] = v;
        else
          p[v] = p[u];
      }
    }
  }
}
int find(int x) { return x != f[x] ? f[x] = find(f[x]) : f[x]; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    long long w;
    scanf("%d%d%lld", &u, &v, &w);
    add(u, v, w), add(v, u, w);
  }
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    int x;
    scanf("%d", &x);
    add(n + 1, x, 0);
  }
  dijkstra(n + 1);
  int tot = 0;
  for (int i = 1; i <= cnte; i++) {
    if (e[i].from <= n) {
      t[++tot].u = p[e[i].from], t[tot].v = p[e[i].to],
      t[tot].w = dis[e[i].from] + dis[e[i].to] + e[i].w;
    }
  }
  sort(t + 1, t + tot + 1);
  for (int i = 1; i <= n; i++) f[i] = i;
  int cnt = 0;
  long long ans = dis[1];
  for (int i = 1; i <= tot; i++) {
    int fu = find(t[i].u), fv = find(t[i].v);
    long long w = t[i].w;
    if (fu != fv) {
      f[fu] = fv;
      ans += t[i].w;
      cnt++;
      if (cnt == n - 1) break;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
