#include <bits/stdc++.h>
using namespace std;
int n, m, xx, yy, k, vv, se[101000], mb[100100];
vector<pair<int, int> > ma[101000];
int fin(int x) {
  if (se[x] == x) return x;
  return se[x] = fin(se[x]);
}
struct no {
  int fr;
  int to;
  long long va;
} e[2002000];
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    q;
long long di[100100];
bool cs[101000];
bool cmp(no x, no y) { return x.va < y.va; }
int fr[101000];
signed main() {
  memset(di, 0x3f, sizeof di);
  scanf("%d%d", &n, &m);
  int cnt = 0;
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d", &xx, &yy, &vv), ma[xx].push_back({yy, vv}),
        ma[yy].push_back({xx, vv}), cnt++, e[cnt].fr = xx, e[cnt].to = yy,
                                           e[cnt].va = vv;
  di[1] = 0;
  q.push({0, 1});
  while (!q.empty()) {
    pair<long long, int> tmp = q.top();
    q.pop();
    int pl = tmp.second;
    if (di[pl] < tmp.first) continue;
    for (int i = 0; i < ma[pl].size(); i++) {
      int to = ma[pl][i].first, va = ma[pl][i].second;
      if (di[to] > di[pl] + va) di[to] = di[pl] + va, q.push({di[to], to});
    }
  }
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) scanf("%d", &mb[i]), cs[mb[i]] = 1;
  long long ans = 9223372036854775807;
  for (int i = 1; i <= n; i++) {
    if (ans > di[i] && cs[i] == 1) ans = min(ans, di[i]);
    se[i] = i;
  }
  memset(di, 0x3f, sizeof di);
  for (int i = 1; i <= k; i++)
    di[mb[i]] = 0, q.push({0, mb[i]}), fr[mb[i]] = mb[i];
  while (!q.empty()) {
    pair<long long, int> tmp = q.top();
    q.pop();
    int pl = tmp.second;
    if (di[pl] < tmp.first) continue;
    for (int i = 0; i < ma[pl].size(); i++) {
      int to = ma[pl][i].first, va = ma[pl][i].second;
      if (di[to] > di[pl] + va)
        di[to] = di[pl] + va, q.push({di[to], to}), fr[to] = fr[pl];
    }
  }
  for (int i = 1; i <= cnt; i++) {
    e[i].va = di[e[i].fr] + di[e[i].to] + e[i].va;
    e[i].fr = fr[e[i].fr];
    e[i].to = fr[e[i].to];
  }
  sort(e + 1, e + 1 + cnt, cmp);
  int co = 0;
  for (int i = 1; i <= cnt; i++) {
    int fx = fin(e[i].fr), fy = fin(e[i].to);
    if (fx != fy) ans += e[i].va, se[fx] = fy, co++;
    if (co == n - 1) break;
  }
  cout << ans;
}
