#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
const long long inf = 1e17 + 3;
int n, m, k;
pair<long long, long long> d[N];
int cha[N];
int rnk[N];
vector<pair<long long, long long> > adj[N];
vector<int> portal;
long long res = 1e17 + 3;
pair<long long, long long> ma[N];
bool vs[N];
long long dis[N];
struct E {
  int u, v;
  long long w;
};
E edge[N];
void dijkstra_1() {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  memset(dis, 0x3f, sizeof dis);
  dis[1] = 0;
  pq.push({0, 1});
  while (pq.size()) {
    int p = pq.top().second;
    long long pd = pq.top().first;
    pq.pop();
    if (pd != dis[p]) continue;
    for (pair<long long, long long> top : adj[p]) {
      int u = top.first;
      long long w = top.second;
      if (dis[u] > dis[p] + w) {
        dis[u] = dis[p] + w;
        pq.push({dis[u], u});
      }
    }
  }
}
int findcha(int u) {
  if (cha[u] != u) cha[u] = findcha(cha[u]);
  return cha[u];
}
bool join(int u, int v) {
  u = findcha(u);
  v = findcha(v);
  if (u == v) return false;
  if (rnk[u] == rnk[v]) rnk[u]++;
  if (rnk[u] > rnk[v])
    cha[v] = u;
  else
    cha[u] = v;
  return true;
}
void dijkstra() {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  for (int u : portal) d[u].first = 0, d[u].second = u, pq.push({0, u});
  while (pq.size()) {
    int p = pq.top().second;
    long long pd = pq.top().first;
    pq.pop();
    if (pd != d[p].first) continue;
    for (pair<long long, long long> top : adj[p]) {
      int u = top.first;
      long long w = top.second;
      if (d[u].first > d[p].first + w) {
        d[u].first = d[p].first + w;
        d[u].second = d[p].second;
        pq.push({d[u].first, u});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
    cha[u] = u;
    cha[v] = v;
    edge[i].u = u;
    edge[i].v = v;
    edge[i].w = w;
  }
  cin >> k;
  for (int i = 1; i <= k; i++) {
    int x;
    cin >> x;
    portal.push_back(x);
  }
  memset(vs, false, sizeof vs);
  dijkstra_1();
  for (int u : portal) res = min(res, dis[u]);
  while (portal.size() > 1) {
    for (int i = 1; i <= n; i++)
      ma[i].first = d[i].first = inf, d[i].second = 0, adj[i].clear();
    for (int i = 1; i <= m; i++) {
      int u = edge[i].u, v = edge[i].v, w = edge[i].w;
      adj[u].push_back({v, w});
      adj[v].push_back({u, w});
    }
    dijkstra();
    for (int i = 1; i <= m; i++) {
      int u = edge[i].u, v = edge[i].v, w = edge[i].w;
      if (d[u].second != d[v].second) {
        int id1 = d[u].second;
        int id2 = d[v].second;
        if (ma[id1].first > d[u].first + w + d[v].first) {
          ma[id1].first = d[u].first + w + d[v].first;
          ma[id1].second = id2;
        }
        if (ma[id2].first > d[u].first + w + d[v].first) {
          ma[id2].first = d[u].first + w + d[v].first;
          ma[id2].second = id1;
        }
      }
    }
    for (int u : portal) {
      int v = ma[u].second;
      if (join(u, v)) res += ma[u].first;
    }
    set<int> ms;
    for (int u : portal) {
      u = findcha(u);
      ms.insert(u);
    }
    portal.clear();
    for (auto it = ms.begin(); it != ms.end(); it++) {
      portal.push_back(*it);
    }
    for (int i = 1; i <= m; i++) {
      edge[i].u = findcha(edge[i].u);
      edge[i].v = findcha(edge[i].v);
    }
  }
  cout << res;
}
