#include <bits/stdc++.h>
using namespace std;
const int MX = (1 << 20);
class Disjoint_Set {
 public:
  int sz[MX], P[MX];
  int find_(int x) {
    if (x != P[x]) P[x] = find_(P[x]);
    return P[x];
  }
  int comp;
  void init(int N) {
    for (int j = 1; j <= N; j++) sz[j] = 1, P[j] = j;
    comp = N;
  }
  bool same(int x, int y) { return find_(x) == find_(y); }
  int compsize(int node) { return sz[find_(node)]; }
  bool merge_(int x, int y) {
    int px = find_(x), py = find_(y);
    if (px == py) return false;
    if (sz[px] < sz[py]) swap(px, py);
    P[py] = px;
    comp--;
    sz[px] += sz[py];
    return true;
  }
} G;
struct state {
  long long cost;
  int node, bitch;
  state() {}
  state(long long cost, int node, int bitch)
      : cost(cost), node(node), bitch(bitch) {}
};
bool operator<(const state &A, const state &B) { return A.cost > B.cost; }
vector<pair<long long, pair<int, int> > > E;
vector<pair<int, int> > v[MX];
int n, m;
int last[MX], good[MX];
long long dis[MX];
int main() {
  scanf("%d %d", &n, &m);
  for (int j = 1; j <= m; j++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    v[a].push_back({b, c});
    v[b].push_back({a, c});
  }
  priority_queue<state> Q;
  int kk, somecity;
  scanf("%d", &kk);
  while (kk--) {
    int x;
    scanf("%d", &x);
    somecity = x;
    Q.push(state(0, x, x));
  }
  for (int j = 1; j <= n; j++) dis[j] = (1ll << 62), last[j] = -1;
  while (!Q.empty()) {
    long long cost = Q.top().cost, x = Q.top().node, bitch = Q.top().bitch;
    Q.pop();
    if (last[x] == -1) {
      last[x] = bitch;
      dis[x] = cost;
    } else {
      E.push_back(make_pair(dis[x] + cost, make_pair(bitch, last[x])));
      continue;
    }
    for (auto pp : v[x]) {
      if (last[pp.first] == bitch) continue;
      Q.push(state(cost + pp.second, pp.first, bitch));
    }
  }
  G.init(n);
  sort(E.begin(), E.end());
  long long ans = 0;
  for (auto e : E) {
    int u = e.second.first, uu = e.second.second;
    if (G.merge_(u, uu)) ans += e.first;
  }
  for (int j = 1; j <= n; j++)
    if (G.find_(j) == G.find_(somecity)) {
      good[j] = 1;
    }
  for (int j = 1; j <= n; j++) dis[j] = (1ll << 62);
  priority_queue<pair<long long, int> > q;
  q.push({0, 1});
  dis[1] = 0;
  while (!q.empty()) {
    long long cost = -q.top().first;
    int x = q.top().second;
    q.pop();
    if (good[x]) {
      ans += cost;
      break;
    }
    for (auto pp : v[x]) {
      long long ncost = cost + pp.second, nxt = pp.first;
      if (dis[nxt] > ncost) {
        dis[nxt] = ncost;
        q.push({-ncost, nxt});
      }
    }
  }
  cout << ans << endl;
}
