#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:25600000")
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-9;
const long long INF = 1000000000000000000ll;
long long n, m, k;
vector<vector<pair<long long, long long>>> g;
long long dist[102400];
long long nearest[102400];
bool portal[102400];
void dijkstra() {
  set<pair<long long, long long>> s;
  for (long long i = 0; i < n; ++i)
    if (portal[i]) {
      s.insert(make_pair(0, i));
      dist[i] = 0;
      nearest[i] = i;
    }
  while (!s.empty()) {
    assert(s.begin()->first >= 0);
    long long w = s.begin()->first;
    long long v = s.begin()->second;
    s.erase(s.begin());
    for (long long i = 0; i < g[v].size(); ++i) {
      long long vn = g[v][i].first;
      long long wn = w + g[v][i].second;
      if (dist[vn] > wn) {
        s.erase(make_pair(dist[vn], vn));
        dist[vn] = wn;
        nearest[vn] = nearest[v];
        s.insert(make_pair(wn, vn));
      }
    }
  }
}
void updateGraph() {
  vector<long long> nums(n);
  long long cnt = 0;
  for (long long i = 0; i < n; ++i)
    if (portal[i]) nums[i] = cnt++;
  vector<vector<pair<long long, long long>>> res(k);
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < g[i].size(); ++j) {
      long long x = i;
      long long y = g[i][j].first;
      long long U = nums[nearest[x]];
      long long V = nums[nearest[y]];
      if (U != V)
        res[U].push_back(make_pair(V, dist[x] + dist[y] + g[i][j].second));
    }
  g = res;
}
long long p[102400];
long long findParent(long long v) {
  if (p[v] == v) return v;
  return p[v] = findParent(p[v]);
}
void unite(long long x, long long y) {
  if (rand() % 2) swap(x, y);
  if (x != y) p[x] = y;
}
long long findMST() {
  vector<pair<long long, pair<long long, long long>>> edges;
  long long n = g.size();
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < g[i].size(); ++j) {
      long long x = i;
      long long y = g[i][j].first;
      if (x < y) edges.push_back(make_pair(g[i][j].second, make_pair(x, y)));
    }
  sort((edges).begin(), (edges).end());
  for (long long i = 0; i < n; ++i) p[i] = i;
  long long res = 0;
  for (long long i = 0; i < edges.size(); ++i) {
    long long x = edges[i].second.first;
    long long y = edges[i].second.second;
    x = findParent(x);
    y = findParent(y);
    if (x != y) {
      res += edges[i].first;
      unite(x, y);
    }
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) dist[i] = INF;
  g.resize(n);
  for (long long i = 0; i < m; ++i) {
    long long x, y, w;
    cin >> x >> y >> w;
    --x;
    --y;
    g[x].push_back(make_pair(y, w));
    g[y].push_back(make_pair(x, w));
  }
  cin >> k;
  for (long long i = 0; i < k; ++i) {
    long long t;
    cin >> t;
    --t;
    portal[t] = true;
  }
  dijkstra();
  updateGraph();
  long long ans = dist[0] + findMST();
  cout << ans << endl;
}
