#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  long long f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f = ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = f ? -x : x;
}
template <class T>
inline void write(T x) {
  if (x < 0) return putchar('-'), write(-x);
  if (x > 9) write(x / 10);
  putchar('0' + x % 10);
}
const long long N = 1e5 + 5;
struct edge {
  long long next, from, to, w;
} e[N << 1];
struct Edge {
  long long u, v, w;
  bool operator<(const Edge o) const { return w < o.w; }
} E[N];
long long n, m, K, p[N], dis[N], fro[N], vis[N], fa[N], head[N], cnt, tot, ans;
void add(long long u, long long v, long long w) {
  e[++cnt] = {head[u], u, v, w};
  head[u] = cnt;
}
void Dij() {
  priority_queue<pair<long long, long long> > q;
  memset(dis, 0x3f, sizeof(dis));
  for (long long i = 1; i <= K; i++)
    q.push(make_pair(0, p[i])), dis[p[i]] = 0, fro[p[i]] = p[i];
  while (!q.empty()) {
    long long x = q.top().second;
    q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    for (long long i = head[x]; i; i = e[i].next) {
      long long y = e[i].to;
      if (dis[y] > dis[x] + e[i].w) {
        dis[y] = dis[x] + e[i].w, fro[y] = fro[x];
        q.push(make_pair(-dis[y], y));
      }
    }
  }
}
void init() {
  for (long long i = 1; i <= n; i++) fa[i] = i;
}
long long find_fa(long long x) {
  return fa[x] == x ? x : fa[x] = find_fa(fa[x]);
}
void Kruskal() {
  init(), sort(E + 1, E + tot + 1);
  for (long long i = 1; i <= tot; i++) {
    long long x = find_fa(E[i].u), y = find_fa(E[i].v);
    if (x != y) fa[x] = y, ans += E[i].w;
  }
}
signed main() {
  read(n), read(m);
  for (long long i = 1, u, v, w; i <= m; i++) {
    read(u), read(v), read(w);
    add(u, v, w), add(v, u, w);
  }
  read(K);
  for (long long i = 1; i <= K; i++) read(p[i]);
  Dij();
  for (long long i = 1; i <= cnt; i += 2) {
    long long x = fro[e[i].from], y = fro[e[i].to];
    if (x != y) E[++tot] = {x, y, e[i].w + dis[e[i].from] + dis[e[i].to]};
  }
  Kruskal();
  write(ans + dis[1]);
}
