#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 100;
long long par[MAXN];
long long root(long long a) {
  if (par[a] < 0) return a;
  return par[a] = root(par[a]);
}
inline void merge(long long a, long long b) {
  a = root(a);
  b = root(b);
  if (a != b) par[a] = b;
}
vector<pair<long long, long long>> ver[MAXN];
vector<pair<long long, pair<long long, long long>>> edge;
long long dis[MAXN], ner[MAXN];
set<pair<long long, long long>> st;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long x, y, w;
    cin >> x >> y >> w;
    x--, y--;
    ver[x].push_back({y, w});
    ver[y].push_back({x, w});
    edge.push_back({w, {x, y}});
  }
  memset(dis, 63, sizeof dis);
  memset(par, -1, sizeof par);
  long long k;
  cin >> k;
  long long tof = 0;
  for (long long i = 0; i < k; i++) {
    long long x;
    cin >> x;
    x--;
    dis[x] = 0;
    ner[x] = x;
    st.insert({0, x});
    if (x == 0) tof = 1;
  }
  while (st.size()) {
    long long v = st.begin()->second;
    st.erase(st.begin());
    for (auto e : ver[v]) {
      long long u = e.first;
      long long w = e.second;
      if (dis[v] + w < dis[u]) {
        st.erase({dis[u], u});
        dis[u] = dis[v] + w;
        ner[u] = ner[v];
        st.insert({dis[u], u});
      }
    }
  }
  for (long long i = 0; i < m; i++) {
    edge[i].first += dis[edge[i].second.first] + dis[edge[i].second.second];
    edge[i].second.first = ner[edge[i].second.first];
    edge[i].second.second = ner[edge[i].second.second];
  }
  sort(edge.begin(), edge.end());
  long long ans = 0;
  for (auto e : edge) {
    long long x = e.second.first;
    long long y = e.second.second;
    long long w = e.first;
    if (root(x) != root(y)) {
      ans += w;
      merge(x, y);
    }
  }
  cout << ans + (1 - tof) * dis[0] << '\n';
}
