#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e5 + 9, INF = 1e16;
long long n, m, a, b, c, t, d[MAX], p[MAX], ans, f[MAX];
vector<pair<long long, int> > g[MAX];
vector<pair<long long, pair<int, int> > > edge;
set<pair<long long, int> > s;
int root(int v) { return f[v] < 0 ? v : f[v] = root(f[v]); }
bool merge(int a, int b) {
  if ((a = root(a)) == (b = root(b))) return false;
  if (f[a] < f[b]) swap(a, b);
  return f[a] += f[b], f[b] = a, true;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  memset(f, -1, sizeof f);
  for (int i = 0; i < MAX; i++) d[i] = INF;
  cin >> n >> m;
  for (int i = 0; i < m; i++)
    cin >> a >> b >> c, a--, b--, g[a].push_back({b, c}),
        g[b].push_back({a, c});
  cin >> t;
  for (int i = 0; i < t; i++) cin >> a, a--, d[a] = 0, p[a] = a;
  for (int i = 0; i < n; i++) s.insert({d[i], i});
  while (s.size()) {
    long long v = (*s.begin()).second;
    for (auto u : g[v])
      if (d[u.first] > d[v] + u.second)
        s.erase({d[u.first], u.first}), d[u.first] = d[v] + u.second,
                                        p[u.first] = p[v],
                                        s.insert({d[u.first], u.first});
    s.erase(s.begin());
  }
  for (int i = 0; i < n; i++)
    for (auto j : g[i])
      edge.push_back({j.second + d[i] + d[j.first], {p[i], p[j.first]}});
  sort(edge.begin(), edge.end());
  for (auto i : edge)
    if (merge(i.second.first, i.second.second)) ans += i.first;
  cout << ans + d[0];
}
