#include <bits/stdc++.h>
using namespace std;
long long n;
vector<vector<pair<long long, long long> > > g;
vector<long long> d, p, to_p;
void dij(vector<long long> start) {
  d.resize(n);
  fill(d.begin(), d.end(), 1e18);
  p.resize(n);
  fill(p.begin(), p.end(), -1);
  set<pair<long long, long long> > q;
  long long ind = 0;
  to_p.resize(n);
  fill(to_p.begin(), to_p.end(), -1);
  for (auto &i : start) {
    d[i] = 0;
    to_p[i] = ind;
    q.insert({d[i], i});
    ind++;
  }
  while (q.size() > 0) {
    long long v = (*q.begin()).second;
    q.erase(q.begin());
    for (auto e : g[v]) {
      if (1LL * d[v] + e.second < 1LL * d[e.first]) {
        q.erase({d[e.first], e.first});
        d[e.first] = 1LL * d[v] + e.second;
        p[e.first] = v;
        q.insert({d[e.first], e.first});
      }
    }
  }
}
struct DSU {
  vector<long long> p;
  vector<long long> sz;
  void cResize(long long n) {
    p.resize(n);
    sz.resize(n);
    for (long long i = 0; i < n; i++) {
      p[i] = i;
      sz[i] = 1;
    }
  }
  long long cFind(long long x) {
    if (x >= p.size()) return 0;
    if (p[x] == x) return x;
    p[x] = cFind(p[x]);
    return p[x];
  }
  void cUnion(long long a, long long b) {
    a = cFind(a);
    b = cFind(b);
    if (sz[a] > sz[b]) {
      swap(a, b);
    }
    p[a] = b;
    sz[b] += sz[a];
  }
};
long long upd2p(long long v) {
  if (to_p[v] == -1) {
    assert(p[v] != -1);
    to_p[v] = upd2p(p[v]);
  }
  return to_p[v];
}
signed main() {
  long long m;
  cin >> n >> m;
  g.resize(n);
  long long a, b, c;
  for (long long i = 0; i < m; i++) {
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  long long k;
  cin >> k;
  vector<long long> kk(k);
  for (auto &i : kk) {
    cin >> i;
    i--;
  }
  dij(kk);
  for (long long i = 0; i < n; i++) {
    if (to_p[i] == -1) {
      upd2p(i);
    }
  }
  vector<pair<long long, pair<long long, long long> > > new_edges;
  for (long long v = 0; v < n; v++) {
    for (auto pp : g[v]) {
      long long u = pp.first;
      if (to_p[v] != to_p[u]) {
        new_edges.push_back({d[v] + pp.second + d[u], {to_p[v], to_p[u]}});
      }
    }
  }
  DSU dsu;
  dsu.cResize(k);
  sort(new_edges.begin(), new_edges.end());
  long long ans = 0;
  for (auto &e : new_edges) {
    long long v = e.second.first;
    long long u = e.second.second;
    if (dsu.cFind(v) != dsu.cFind(u)) {
      dsu.cUnion(v, u);
      ans += 1LL * e.first;
    }
  }
  ans += d[0];
  cout << ans;
  return 0;
}
