#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
long long int h[N], fad[N], e1[N], e2[N], co[N], par[N];
vector<pair<long long int, long long int>> v[N];
bool por[N];
bool cmp(pair<pair<long long int, long long int>, long long int> p1,
         pair<pair<long long int, long long int>, long long int> p2) {
  return p1.second < p2.second;
}
int fin(int x) { return (x == par[x]) ? x : par[x] = fin(par[x]); }
int main() {
  iota(par, par + N - 10, 0);
  fill(h, h + N - 10, 1e16);
  long long int n, m, k;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long int u1, u2, c;
    cin >> u1 >> u2 >> c;
    u1--;
    u2--;
    e1[i] = u1;
    e2[i] = u2;
    co[i] = c;
    v[u1].emplace_back(make_pair(u2, c));
    v[u2].emplace_back(make_pair(u1, c));
  }
  cin >> k;
  set<pair<long long int, long long int>> s;
  s.clear();
  for (int i = 0; i < k; i++) {
    long long int x;
    cin >> x;
    x--;
    h[x] = 0;
    por[x] = 1;
    fad[x] = x;
    s.insert(make_pair(0, x));
  }
  while (s.size() > 0) {
    auto p1 = *s.begin();
    s.erase(p1);
    for (auto u : v[p1.second]) {
      if (u.second + p1.first < h[u.first]) {
        s.erase(make_pair(h[u.first], u.first));
        fad[u.first] = fad[p1.second];
        h[u.first] = u.second + p1.first;
        s.insert(make_pair(h[u.first], u.first));
      }
    }
  }
  vector<pair<pair<long long int, long long int>, long long int>> edg;
  edg.clear();
  for (int i = 0; i < m; i++) {
    if (fad[e1[i]] != fad[e2[i]]) {
      edg.emplace_back(make_pair(make_pair(fad[e1[i]], fad[e2[i]]),
                                 co[i] + h[e1[i]] + h[e2[i]]));
    }
  }
  long long int ans = h[0];
  sort(edg.begin(), edg.end(), cmp);
  for (auto u : edg) {
    long long int u1 = u.first.first, u2 = u.first.second, c = u.second;
    u1 = fin(u1);
    u2 = fin(u2);
    if (u1 != u2) {
      par[u1] = u2;
      ans += c;
    }
  }
  cout << ans;
}
