#include <bits/stdc++.h>
using namespace ::std;
const long long maxn = 1e5 + 500;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 500;
vector<pair<long long, long long> > ger[maxn];
bool por[maxn];
long long minn[maxn];
long long kires[maxn];
long long ans = 0;
long long par[maxn];
long long find_par(long long a) {
  if (par[a] == a) {
    return a;
  }
  par[a] = find_par(par[a]);
  return par[a];
}
void merg(long long a, long long b) {
  b = find_par(b);
  a = find_par(a);
  if (a != b) {
    par[a] = b;
  }
}
void find_naz() {
  set<pair<long long, long long> > st;
  st.insert(make_pair(1, 0));
  while (!st.empty()) {
    pair<long long, long long> e = (*(st.begin()));
    st.erase(e);
    long long v = e.second;
    long long w = e.first;
    if (minn[v] == 0) {
      minn[v] = w;
      if (por[v]) {
        ans += w - 1;
        return;
      }
      for (long long i = 0; i < ger[v].size(); i++) {
        long long u = ger[v][i].first;
        if (minn[u] == 0) {
          st.insert(make_pair(w + ger[v][i].second, u));
        }
      }
    }
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    par[i] = i;
  }
  for (long long i = 0; i < m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    v--;
    u--;
    ger[u].push_back(make_pair(v, w));
    ger[v].push_back(make_pair(u, w));
  }
  long long k;
  cin >> k;
  for (long long i = 0; i < k; i++) {
    long long v;
    cin >> v;
    v--;
    por[v] = 1;
  }
  find_naz();
  fill(minn, minn + n, 0);
  set<pair<long long, pair<long long, long long> > > st;
  for (long long i = 0; i < n; i++) {
    if (por[i]) {
      st.insert(make_pair(1, make_pair(i, i)));
    }
  }
  while (!st.empty()) {
    pair<long long, pair<long long, long long> > e = (*(st.begin()));
    st.erase(e);
    long long v = e.second.first;
    long long w = e.first;
    long long ki = find_par(e.second.second);
    if (minn[v] == 0) {
      minn[v] = w;
      kires[v] = ki;
      for (long long i = 0; i < ger[v].size(); i++) {
        long long u = ger[v][i].first;
        st.insert(make_pair(ger[v][i].second + w, make_pair(u, ki)));
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    merg(i, kires[i]);
  }
  vector<pair<long long, pair<long long, long long> > > yal;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < ger[i].size(); j++) {
      long long u = ger[i][j].first;
      long long w = ger[i][j].second;
      yal.push_back(make_pair(w + minn[i] + minn[u] - 2,
                              make_pair(find_par(u), find_par(i))));
    }
  }
  sort(yal.begin(), yal.end());
  for (long long i = 0; i < 2 * m; i++) {
    long long w = yal[i].first;
    long long v = yal[i].second.first;
    long long u = yal[i].second.second;
    if (find_par(v) != find_par(u)) {
      merg(v, u);
      ans += w;
    }
  }
  cout << ans;
}
