#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 59;
const int maxn = 123456;
vector<pair<int, long long> > edge[maxn];
priority_queue<pair<long long, int> > heap;
priority_queue<pair<long long, pair<int, int> > > edges;
long long sum = 0;
int p[maxn];
bool crit[maxn], been[maxn];
bool last[maxn];
pair<long long, int> shortest[maxn];
map<int, long long> d[maxn];
int findrep(int a) { return (p[a] == a) ? (a) : (p[a] = findrep(p[a])); }
void join(int a, int b) { p[findrep(b)] = findrep(a); }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    shortest[i] = make_pair(inf, -1);
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    long long d;
    scanf("%d%d%I64d", &x, &y, &d);
    x--;
    y--;
    edge[x].push_back(make_pair(y, d));
    edge[y].push_back(make_pair(x, d));
  }
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    int x;
    scanf("%d", &x);
    x--;
    crit[x] = true;
    shortest[x] = make_pair(0, x);
    heap.push(make_pair(0, x));
  }
  while (!heap.empty()) {
    int at = heap.top().second;
    long long dst = -heap.top().first;
    heap.pop();
    if (been[at]) continue;
    been[at] = true;
    for (int i = 0; i < edge[at].size(); i++) {
      int to = edge[at][i].first, from = shortest[at].second;
      int fin = shortest[to].second;
      long long len = dst + edge[at][i].second;
      if (fin != -1 && fin != from) {
        map<int, long long>::iterator it = d[from].find(fin);
        if (it == d[from].end() || it->second > len + shortest[to].first) {
          d[from][fin] = len + shortest[to].first;
          d[fin][from] = len + shortest[to].first;
        }
      }
      if (len < shortest[to].first) {
        shortest[to] = make_pair(len, shortest[at].second);
        heap.push(make_pair(-len, to));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    map<int, long long>::iterator it = d[i].upper_bound(i);
    while (it != d[i].end()) {
      edges.push(make_pair(-it->second, make_pair(i, it->first)));
      it++;
    }
  }
  while (edges.empty() == false) {
    long long w = -edges.top().first;
    int a = edges.top().second.first, b = edges.top().second.second;
    edges.pop();
    if (findrep(a) != findrep(b)) {
      sum += w;
      join(a, b);
    }
  }
  if (crit[0] == false) {
    heap.push(make_pair(0, 0));
    while (!heap.empty()) {
      int at = heap.top().second;
      long long dst = -heap.top().first;
      heap.pop();
      if (last[at]) continue;
      last[at] = true;
      if (crit[at] == true) {
        sum += dst;
        break;
      }
      for (int i = 0; i < edge[at].size(); i++) {
        int to = edge[at][i].first;
        heap.push(make_pair(-(dst + edge[at][i].second), to));
      }
    }
  }
  printf("%I64d\n", sum);
  return 0;
}
