#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const long long int INF = 1e18;
int n;
vector<pair<int, int> > adj[N];
bool portal[N];
struct elem {
  int u;
  long long int d;
  bool operator<(const elem &o) const { return d > o.d; }
};
long long int dist[N];
bool vis[N];
int source[N];
void distra() {
  fill(vis, vis + n, false);
  fill(dist, dist + n, INF);
  fill(source, source + n, -1);
  priority_queue<elem> q;
  for (int u = 0; u < (int)(n); u++)
    if (portal[u]) {
      dist[u] = 0;
      source[u] = u;
      q.push((elem){u, 0});
    }
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int u = t.u;
    long long int d = t.d;
    if (vis[u]) continue;
    vis[u] = true;
    for (auto e : adj[u]) {
      int v = e.first, c = e.second;
      if (dist[u] + c < dist[v]) {
        dist[v] = dist[u] + c;
        source[v] = source[u];
        q.push((elem){v, dist[v]});
      }
    }
  }
}
struct edge {
  int u, v;
  long long int d;
  bool operator<(const edge &o) const { return d < o.d; }
};
int pre[N];
int find(int x) { return pre[x] = (pre[x] == x ? x : find(pre[x])); }
bool merge(int x, int y) {
  int a = find(x), b = find(y);
  if (a != b) {
    pre[b] = a;
    return true;
  } else
    return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int m;
  cin >> n >> m;
  while (m--) {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    adj[u].emplace_back(v, c);
    adj[v].emplace_back(u, c);
  }
  int k;
  cin >> k;
  while (k--) {
    int u;
    cin >> u;
    u--;
    portal[u] = true;
  }
  distra();
  vector<edge> edges;
  for (int u = 0; u < (int)(n); u++)
    for (auto e : adj[u]) {
      int v = e.first, c = e.second;
      if (u < v && source[u] != source[v])
        edges.push_back((edge){source[u], source[v], dist[u] + dist[v] + c});
    }
  sort((edges).begin(), (edges).end());
  long long int res = dist[0];
  cerr << "res"
       << "=" << res << endl;
  ;
  for (int u = 0; u < (int)(n); u++) pre[u] = u;
  for (auto e : edges) {
    if (merge(e.u, e.v)) res += e.d;
  }
  cout << res << endl;
  return 0;
}
