#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long INF = 1e17 + 3;
long long n, m, k, par[N], dsupar[N], h[N];
long long d[N], ans;
bool portal[N];
vector<pair<long long, long long> > v[N];
vector<long long> portals;
set<pair<long long, long long> > s;
vector<pair<pair<long long, long long>, long long> > edge, first_edge;
void dijkstra() {
  for (long long i = 0; i < k; ++i) {
    d[portals[i]] = 0;
    par[portals[i]] = portals[i];
    s.insert(make_pair(0, portals[i]));
  }
  long long now, kid;
  while (s.size()) {
    now = s.begin()->second;
    s.erase(s.begin());
    for (long long i = 0; i < v[now].size(); ++i) {
      kid = v[now][i].first;
      if (d[kid] > d[now] + v[now][i].second) {
        s.erase(make_pair(d[kid], kid));
        d[kid] = d[now] + v[now][i].second;
        par[kid] = par[now];
        s.insert(make_pair(d[kid], kid));
      }
    }
  }
}
bool cmp(pair<pair<long long, long long>, long long> aa,
         pair<pair<long long, long long>, long long> bb) {
  return aa.second < bb.second;
}
long long get_par(long long x) {
  if (x == dsupar[x]) return x;
  dsupar[x] = get_par(dsupar[x]);
  return dsupar[x];
}
void merge(long long xx, long long yy) {
  if (h[xx] < h[yy]) swap(xx, yy);
  if (h[xx] == h[yy]) h[xx]++;
  dsupar[yy] = xx;
}
int32_t main() {
  for (long long i = 0; i < N; ++i) d[i] = INF;
  cin >> n >> m;
  long long x, u, w;
  for (long long i = 0; i < m; ++i) {
    cin >> x >> u >> w;
    v[x].push_back(make_pair(u, w));
    v[u].push_back(make_pair(x, w));
    first_edge.push_back(make_pair(make_pair(x, u), w));
  }
  cin >> k;
  long long help;
  for (long long i = 0; i < k; ++i) {
    cin >> help;
    portal[help] = true;
    portals.push_back(help);
  }
  dijkstra();
  long long from, too, ww;
  for (long long i = 0; i < N; ++i) dsupar[i] = i;
  for (long long i = 0; i < m; ++i) {
    from = first_edge[i].first.first, too = first_edge[i].first.second,
    ww = first_edge[i].second;
    if (par[from] == par[too]) continue;
    edge.push_back(
        make_pair(make_pair(par[from], par[too]), d[from] + d[too] + ww));
  }
  sort(edge.begin(), edge.end(), cmp);
  for (long long i = 0; i < edge.size(); ++i) {
    from = edge[i].first.first, too = edge[i].first.second, ww = edge[i].second;
    if (get_par(from) == get_par(too)) continue;
    ans += ww;
    merge(get_par(from), get_par(too));
  }
  if (!portal[1]) ans += d[1];
  cout << ans;
}
