#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = 1000 * 1000 * 1000;
const double EPS = 1e-9;
const int MAXN = 100100;
struct Edge {
  int from, to;
  long long weight;
  Edge(int from, int to, long long weight)
      : from(from), to(to), weight(weight) {}
  bool operator<(const Edge &o) const { return weight < o.weight; }
};
vector<vector<Edge> > g;
long long dst[MAXN];
int p[MAXN];
int parent[MAXN];
int rnk[MAXN];
int N, M, Q;
void addEdge(int u, int v, int weight) {
  g[u].push_back(Edge(u, v, weight));
  g[v].push_back(Edge(v, u, weight));
}
void Dijkstra(const vector<int> &start) {
  for (int i = 0; i < N; ++i) {
    dst[i] = 1LL * INF * INF;
  }
  set<pair<long long, int> > q;
  for (int i = 0; i < (int)start.size(); ++i) {
    dst[start[i]] = 0;
    p[start[i]] = start[i];
    q.insert(make_pair(dst[start[i]], start[i]));
  }
  while (!q.empty()) {
    int v = q.begin()->second;
    q.erase(q.begin());
    for (int i = 0; i < (int)g[v].size(); ++i) {
      int to = g[v][i].to, weight = g[v][i].weight;
      if (dst[to] > dst[v] + weight) {
        q.erase(make_pair(dst[to], to));
        dst[to] = dst[v] + weight;
        p[to] = p[v];
        q.insert(make_pair(dst[to], to));
      }
    }
  }
}
void init() {
  for (int i = 0; i < Q; ++i) {
    parent[i] = i;
  }
}
int findSet(int v) {
  if (v == parent[v]) {
    return v;
  }
  return parent[v] = findSet(parent[v]);
}
bool uniteSets(int u, int v) {
  u = findSet(u), v = findSet(v);
  if (u != v) {
    if (rnk[u] < rnk[v]) {
      swap(u, v);
    }
    parent[v] = u;
    if (rnk[u] == rnk[v]) {
      ++rnk[u];
    }
    return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &N, &M);
  g.resize(N);
  for (int i = 0; i < M; ++i) {
    int u, v, weight;
    scanf("%d%d%d", &u, &v, &weight);
    addEdge(u - 1, v - 1, weight);
  }
  scanf("%d", &Q);
  vector<int> portals;
  map<int, int> mp;
  bool isInFirst = false;
  for (int i = 0; i < Q; ++i) {
    int v;
    scanf("%d", &v);
    if (v == 1) {
      isInFirst = true;
    }
    portals.push_back(v - 1);
    mp.insert(make_pair(v - 1, i));
  }
  Dijkstra(portals);
  vector<Edge> edges;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < (int)g[i].size(); ++j) {
      edges.push_back(
          Edge(mp[p[g[i][j].from]], mp[p[g[i][j].to]],
               dst[g[i][j].from] + g[i][j].weight + dst[g[i][j].to]));
    }
  sort(edges.begin(), edges.end());
  init();
  long long totalWeight = 0;
  for (int i = 0; i < (int)edges.size(); ++i)
    if (uniteSets(edges[i].from, edges[i].to)) {
      totalWeight += edges[i].weight;
    }
  if (!isInFirst) {
    totalWeight += dst[0];
  }
  printf("%I64d", totalWeight);
  return 0;
}
