#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
inline long long input() {
  long long n;
  cin >> n;
  return n;
}
string base2(long long n) {
  string a = "";
  while (n >= 2) {
    a += (char)(n % 2 + '0');
    n /= 2;
  }
  a += (char)(n + '0');
  reverse((a).begin(), (a).end());
  return a;
}
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const long long INF = 8e18;
long long pw(long long a, long long b, long long mod) {
  return (!b ? 1
             : (b & 1 ? (a * pw(a * a % mod, b / 2, mod)) % mod
                      : pw(a * a % mod, b / 2, mod)));
}
int n, m, mark[MAXN], king[MAXN], par[MAXN], sz[MAXN];
vector<pair<int, int> > G[MAXN];
vector<int> M;
long long dis[MAXN];
pair<long long, pair<long long, long long> > E[MAXN];
vector<pair<long long, pair<long long, long long> > > E2;
int GET(int x) { return ((x == par[x]) ? x : par[x] = GET(par[x])); }
bool unify(int x, int y) {
  int v = GET(x), u = GET(y);
  if (v == u) return 0;
  if (sz[u] > sz[v]) {
    swap(u, v);
  }
  par[u] = v;
  sz[v] += sz[u];
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) dis[i] = 1e18, sz[i] = 1, par[i] = i;
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a].push_back(make_pair(b, c));
    G[b].push_back(make_pair(a, c));
    E[i] = make_pair(c, make_pair(a, b));
  }
  set<pair<long long, long long> > st;
  int k;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    int a;
    cin >> a;
    M.push_back(a);
    king[a] = a;
    st.insert(make_pair(0, a));
    dis[a] = 0;
  }
  while (!st.empty()) {
    pair<long long, long long> cu = *st.begin();
    st.erase(st.begin());
    int v = cu.second;
    if (mark[v]) {
      continue;
    }
    mark[v] = 1;
    for (auto y : G[v]) {
      long long u = y.first, cost = y.second;
      if (dis[u] > dis[v] + cost) {
        king[u] = king[v];
        dis[u] = dis[v] + cost;
        st.insert(make_pair(dis[u], u));
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    long long v = E[i].second.first, u = E[i].second.second, cost = E[i].first;
    if (king[u] != king[v]) {
      E2.push_back(
          make_pair(dis[v] + dis[u] + cost, make_pair(king[u], king[v])));
    }
  }
  sort((E2).begin(), (E2).end());
  long long MST = 0;
  for (auto x : E2) {
    long long u = x.second.first, v = x.second.second, cost = x.first;
    if (unify(v, u)) {
      MST += cost;
    }
  }
  set<long long> second;
  for (auto x : M) {
    second.insert(GET(x));
  }
  if ((int)second.size() > 1) {
    return cout << 1e18, 0;
  }
  cout << MST + dis[1];
  return 0;
}
