#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 5, Mod = 1e9 + 7, MAXN = 1e5, Lg = 20, M = 1e7 + 10,
                P = 727, Sq = 320;
const long long inf = 3e18 + 10;
long long n, dis[N], k, par[N], parent[N], is[N], m;
vector<long long> pt;
set<pair<long long, long long> > s;
vector<pair<long long, long long> > adj[N];
set<pair<long long, pair<long long, long long> > > ms;
vector<pair<long long, pair<long long, long long> > > e;
inline void Djkstra() {
  for (long long i = 1; i <= n; i++) dis[i] = inf;
  for (long long i = 0; i < k; i++) {
    dis[pt[i]] = 0, par[pt[i]] = pt[i];
    s.insert(make_pair(0ll, pt[i]));
  }
  while (s.size()) {
    pair<long long, long long> u = (*s.begin());
    swap(u.first, u.second);
    s.erase(s.begin());
    for (long long i = 0; i < (long long)adj[u.first].size(); i++) {
      long long x = adj[u.first][i].first, z = adj[u.first][i].second;
      if ((dis[x] > dis[u.first] + z) ||
          (dis[x] == dis[u.first] + z && par[x] > par[u.first])) {
        s.erase(make_pair(dis[x], x));
        dis[x] = dis[u.first] + z, par[x] = par[u.first];
        s.insert(make_pair(dis[x], x));
      }
    }
  }
}
long long Find(long long x) {
  if (parent[x] < 0) return x;
  return (parent[x] = Find(parent[x]));
}
inline void Mrg(long long x, long long y) {
  x = Find(x), y = Find(y);
  if (-parent[x] > -parent[y]) {
    parent[x] += parent[y];
    parent[y] = x;
  } else {
    parent[y] += parent[x];
    parent[x] = y;
  }
}
inline long long Mst() {
  long long res = 0;
  for (long long i = 0; i < k; i++) {
    long long x = pt[i];
    for (long long j = 0; j < (long long)adj[x].size(); j++)
      if (is[adj[x][j].first])
        ms.insert(make_pair(adj[x][j].second, make_pair(x, adj[x][j].first)));
    parent[x] = -1;
  }
  while (ms.size()) {
    pair<long long, pair<long long, long long> > u;
    u = (*ms.begin());
    ms.erase(ms.begin());
    long long x = u.second.first, y = u.second.second, z = u.first;
    if (Find(x) == Find(y)) continue;
    Mrg(x, y);
    res += z;
  }
  return res;
}
int32_t main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= m; i++) {
    long long x, y, z;
    scanf("%lld%lld%lld", &x, &y, &z);
    adj[x].push_back(make_pair(y, z)), adj[y].push_back(make_pair(x, z));
    e.push_back(make_pair(z, make_pair(x, y)));
  }
  scanf("%lld", &k);
  for (long long i = 1; i <= k; i++) {
    long long x;
    scanf("%lld", &x);
    pt.push_back(x);
    is[x] = 1;
  }
  Djkstra();
  for (long long i = 0; i < m; i++) {
    long long x = e[i].second.first, y = e[i].second.second, z = e[i].first;
    if (par[x] == par[y]) continue;
    adj[par[x]].push_back(make_pair(par[y], dis[x] + dis[y] + z));
    adj[par[y]].push_back(make_pair(par[x], dis[x] + dis[y] + z));
  }
  long long ans = Mst() + dis[1];
  printf("%lld", ans);
  return 0;
}
