// be name ooo ...
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define LOCAL_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define Rep(i,first_val,end_val) for(ll i=first_val;i<end_val;i+=1)

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n, A; cin >> n >> A;
	vector <ll> tA;
	ll a[n];
	for (ll i=0; i<n; i++) cin >> a[i];
	for (ll i=0; i<n; i++) {
		ll f = 0;
		while (i < n && a[i] == A) {
			f++;
			i++;
		}
		if(f != 0) tA.push_back(f);
	}
	if(tA.size() == 0) {
		if(A == 1) cout << "2";
		else	cout << "1";
		return 0;
	}
	vector <ll> valid;
	map <ll,ll> M;
	ll A_i = 0;
	ll total = tA[A_i];
	for(ll i=0; i<n; i++) {
		if (a[i] == A) {
			for(vector <ll>::iterator it = valid.begin(); it!=valid.end(); it++) {
				if( M[*it] < total ) {
					valid.erase(it,it+1);
					it--;
				}
			}
			A_i++;
			if( A_i == tA.size() ) break;
			total += tA[A_i];
			while (i+1 < n && a[i+1] == A) i++;
			continue;
		}
		M[ a[i] ] ++;
		if(M[ a[i] ] == tA[A_i] && A_i == 0)
			valid.push_back ( a[i] );
	}
	if( !valid.empty() )
		cout << valid[0];
	else
		cout << "-1";
}


// be name ooo ...
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define LOCAL_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define Rep(i,first_val,end_val) for(ll i=first_val;i<end_val;i+=1)

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n, A; cin >> n >> A;
	vector <ll> tA;
	ll a[n];
	for (ll i=0; i<n; i++) cin >> a[i];
	for (ll i=0; i<n; i++) {
		ll f = 0;
		while (i < n && a[i] == A) {
			f++;
			i++;
		}
		if(f != 0) tA.push_back(f);
	}
	if(tA.size() == 0) {
		if(A == 1) cout << "2";
		else	cout << "1";
		return 0;
	}
	bool valid[1000005]; fill(valid, valid+1000005, false);
	map <ll,ll> M;
	vector <ll> cur, ok;
	ll A_i = 0;
	ll A_f = 0;
	ll total = tA[A_i];
	for(ll i=0; i<n; i++) {
		if (a[i] == A) {
			for (vector <ll>::iterator it = cur.begin(); it != cur.end(); it++) {
				if (M[*it] < total) {
					valid[*it] = false;
					cur.erase(it,it+1);
					it--;
				}
			}
			A_i++;
			while (i+1<n && a[i+1] == 1)
				i++;
			if( A_i == tA.size() ) break;
			total += tA[A_i];
			continue;
		}
		M[ a[i] ] ++;
		cur.push_back( a[i] );
		if(M[ a[i] ] == tA[A_i] && A_i == 0)
			valid[ a[i] ] = true;
	}
	for(ll i=1;i<=1000000;i++) {
		if(valid[i]) {
			cout << i << "\n";
			return 0;
		}
	}
	cout << "-1";
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int city, road, flour;

	cin >> city >> road >> flour;
	//cout << "-11" << endl;
	int **matrice = new int *[city + 1];

	for(int i = 0; i < city + 1; i++){
		matrice[i] = new int[city + 1];
	}
	//cout << "0" << endl;
	for(int i = 1; i < city + 1; i++){
		for(int j = 1; j < city + 1; j++){
			if(i == j){
				matrice[i][j] = 0;
			}
			else matrice[i][j] = -1;
		}
	}

	//cout << "1" << endl;
	int num1, num2, weight;
	for(int i = 0; i < road; i++){
		cin >> num1 >> num2 >> weight;
		if(matrice[num1][num2] > weight || matrice[num1][num2] < 0){
			matrice[num1][num2] = weight;
			matrice[num2][num1] = weight;
		}

	}
	//cout << "2" << endl;

	int min = 1300000000;
	int *f = new int[flour];
	for(int i = 0; i < flour; i++){
		cin >> f[i];
	}

	sort(f, f + flour);
	//cout << "3" << endl;

	for(int i = 0; i < flour; i++){
		cout << f[i] << " " ;
	}
	for(int i = 0; i < flour; i++){
		for(int j = 1; j < city + 1; j++){
			if(matrice[f[i]][j] > 0 && matrice[f[i]][j] < min) {

				/*int *p = find(f, f + flour, j);
				if(p == f + flour){
					min = matrice[f[i]][j];
				}*/
				int l = 0;
				int r = flour - 1;
				int m;

				while(l <= r){
					m = (l + r)/2;
					if(j > f[m]){
						l = m + 1;
					}
					else if(j < f[m]){
						r = m - 1;
					}
					else{
						goto T;
					}
				}
				min = matrice[f[i]][j];
T:
int k;
			}
		}
	}

	if(min != 1300000000){
		cout << min;
	}
	else cout << "-1";

}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int city, road, flour;

	cin >> city >> road >> flour;

	int **matrice = new int *[city + 1];

	for(int i = 0; i < city + 1; i++){
		matrice[i] = new int[city + 1];
	}

	for(int i = 1; i < city + 1; i++){
		for(int j = 1; j < city + 1; j++){
			if(i == j){
				matrice[i][j] = 0;
			}
			else matrice[i][j] = -1;
		}
	}
	int num1, num2, weight;
	for(int i = 0; i < road; i++){
		cin >> num1 >> num2 >> weight;

		matrice[num1][num2] = weight;
		matrice[num2][num1] = weight;
	}
	int num3;

	int min = 1300000000;
	for(int i = 0; i < flour; i++){
		cin >> num3;

		for(int j = 0; j < city; j++){
			if(matrice[num3][j] > 0 && matrice[num3][j] < min) min = matrice[num3][j];
		}
	}

	if(min != 1300000000){
		cout << min;
	}
	else cout << "-1";
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int city, road, flour;

	cin >> city >> road >> flour;

	int **matrice = new int *[city + 1];

	for(int i = 0; i < city + 1; i++){
		matrice[i] = new int[city + 1];
	}

	for(int i = 1; i < city + 1; i++){
		for(int j = 1; j < city + 1; j++){
			if(i == j){
				matrice[i][j] = 0;
			}
			else matrice[i][j] = -1;
		}
	}
	int num1, num2, weight;
	for(int i = 0; i < road; i++){
		cin >> num1 >> num2 >> weight;
		if(matrice[num1][num2] > weight || matrice[num1][num2] < 0){
			matrice[num1][num2] = weight;
			matrice[num2][num1] = weight;
		}

	}

	int min = 1300000000;
	int *f = new int[flour];
	for(int i = 0; i < flour; i++){
		cin >> f[i];
	}

	for(int i = 0; i < flour; i++){
		for(int j = 1; j < city + 1; j++){
			if(matrice[f[i]][j] > 0 && matrice[f[i]][j] < min) {

				int *p = find(f, f + flour, j);
				if(p == f + flour){
					min = matrice[f[i]][j];
				}/*
				int l = i + 1;
				int r = flour - 1;
				int m;

				while(l < r){
					m = (l + r)/2;
					if(j > f[m]){
						l = m + 1;
					}
					else if(j < f[m]){
						r = m - 1;
					}
					else{
						goto T;
					}
				}
				min = matrice[f[i]][j];
T:
int k;*/
			}
		}
	}

	if(min != 1300000000){
		cout << min;
	}
	else cout << "-1";
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

class node{
public:
	node(){}
	node(int a, int b){
		name = a;
		weight = b;
	}
	int name;
	int weight;

};

int main(){
	int city, road, flour;

	cin >> city >> road >> flour;
	//cout << "-11" << endl;
	/*
	int **matrice = new int *[city + 1];

	for(int i = 0; i < city + 1; i++){
		matrice[i] = new int[city + 1];
	}
	//cout << "0" << endl;*/

	vector <node> *graph = new vector <node> [city + 1];
	/*
	for(int i = 1; i < city + 1; i++){
		for(int j = 1; j < city + 1; j++){
			if(i == j){
				matrice[i][j] = 0;
			}
			else matrice[i][j] = -1;
		}
	}
*/
	//cout << "1" << endl;
	int num1, num2, weight;
	for(int i = 0; i < road; i++){
		cin >> num1 >> num2 >> weight;

				node aa(num2, weight);
				graph[num1].push_back(aa);

				node bb(num1, weight);
				graph[num2].push_back(bb);

		/*
		if(matrice[num1][num2] > weight || matrice[num1][num2] < 0){
			matrice[num1][num2] = weight;
			matrice[num2][num1] = weight;
		}*/

	}
/*vector <node>:: iterator it;
	for(it = graph[num1].begin(); it != graph[num1].end(); it++){
		cout << (*it).weight << endl;
	}*/
	//cout << "2" << endl;

	int min = 1300000000;
	int *f = new int[flour];
	for(int i = 0; i < flour; i++){
		cin >> f[i];
	}

	sort(f, f + flour);
	//cout << "3" << endl;

	for(int i = 0; i < flour; i++){
		vector <node>:: iterator it;
		for(it = graph[f[i]].begin(); it != graph[f[i]].end(); it++){
			if((*it).weight < min) {

				/*int *p = find(f, f + flour, j);
				if(p == f + flour){
					min = matrice[f[i]][j];
				}*/
				int l = 0;
				int r = flour - 1;
				int m;

				while(l <= r){
					m = (l + r)/2;
					if((*it).name > f[m]){
						l = m + 1;
					}
					else if((*it).name < f[m]){
						r = m - 1;
					}
					else{
						goto T;
					}
				}
				min = (*it).weight;
T:
int k;
			}
		}
	}

	if(min != 1300000000){
		cout << min;
	}
	else cout << "-1";

}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

class node{
public:
	node(){}
	node(int a, int b){
		name = a;
		weight = b;
	}
	int name;
	int weight;

};

int main(){
	int city, road, flour;

	cin >> city >> road >> flour;
	//cout << "-11" << endl;
	/*
	int **matrice = new int *[city + 1];

	for(int i = 0; i < city + 1; i++){
		matrice[i] = new int[city + 1];
	}
	//cout << "0" << endl;*/

	vector <node> *graph = new vector <node> [city + 1];
	/*
	for(int i = 1; i < city + 1; i++){
		for(int j = 1; j < city + 1; j++){
			if(i == j){
				matrice[i][j] = 0;
			}
			else matrice[i][j] = -1;
		}
	}
*/
	//cout << "1" << endl;
	int num1, num2, weight;
	for(int i = 0; i < road; i++){
		cin >> num1 >> num2 >> weight;

		if(num1 <= num2){
			node aa(num2, weight);
			graph[num1].push_back(aa);
		}
		else{
			node bb(num2, weight);
			graph[num2].push_back(bb);
		}
		/*
		if(matrice[num1][num2] > weight || matrice[num1][num2] < 0){
			matrice[num1][num2] = weight;
			matrice[num2][num1] = weight;
		}*/

	}
	//cout << "2" << endl;

	int min = 1300000000;
	int *f = new int[flour];
	for(int i = 0; i < flour; i++){
		cin >> f[i];
	}

	sort(f, f + flour);
	//cout << "3" << endl;

	for(int i = 0; i < flour; i++){
		vector <node>:: iterator it;
		for(it = graph[f[i]].begin(); it != graph[f[i]].end(); it++){
			if((*it).weight < min) {

				/*int *p = find(f, f + flour, j);
				if(p == f + flour){
					min = matrice[f[i]][j];
				}*/
				int l = 0;
				int r = flour - 1;
				int m;

				while(l <= r){
					m = (l + r)/2;
					if((*it).name > f[m]){
						l = m + 1;
					}
					else if((*it).name < f[m]){
						r = m - 1;
					}
					else{
						goto T;
					}
				}
				min = (*it).weight;
T:
int k;
			}
		}
	}

	if(min != 1300000000){
		cout << min;
	}
	else cout << "-1";

}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int city, road, flour;

	cin >> city >> road >> flour;

	int **matrice = new int *[city + 1];

	for(int i = 0; i < city + 1; i++){
		matrice[i] = new int[city + 1];
	}

	for(int i = 1; i < city + 1; i++){
		for(int j = 1; j < city + 1; j++){
			if(i == j){
				matrice[i][j] = 0;
			}
			else matrice[i][j] = -1;
		}
	}
	int num1, num2, weight;
	for(int i = 0; i < road; i++){
		cin >> num1 >> num2 >> weight;
		if(matrice[num1][num2] > weight || matrice[num1][num2] < 0){
			matrice[num1][num2] = weight;
			matrice[num2][num1] = weight;
		}

	}

	int min = 1300000000;
	int *f = new int[flour];
	for(int i = 0; i < flour; i++){
		cin >> f[i];
	}

	for(int i = 0; i < flour; i++){
		for(int j = 1; j < city + 1; j++){
			if(matrice[f[i]][j] > 0 && matrice[f[i]][j] < min) {
/*
				int *p = find(f, f + flour, j);
				if(p == f + flour){
					min = matrice[f[i]][j];
				}*/
				int l = i + 1;
				int r = flour - 1;
				int m;

				while(l < r){
					m = (l + r)/2;
					if(j > f[m]){
						l = m + 1;
					}
					else if(j < f[m]){
						r = m - 1;
					}
					else{
						goto T;
					}
				}
				min = matrice[f[i]][j];
T:
int k;
			}
		}
	}

	if(min != 1300000000){
		cout << min;
	}
	else cout << "-1";
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int city, road, flour;

	cin >> city >> road >> flour;

	int **matrice = new int *[city + 1];

	for(int i = 0; i < city + 1; i++){
		matrice[i] = new int[city + 1];
	}

	for(int i = 1; i < city + 1; i++){
		for(int j = 1; j < city + 1; j++){
			if(i == j){
				matrice[i][j] = 0;
			}
			else matrice[i][j] = -1;
		}
	}
	int num1, num2, weight;
	for(int i = 0; i < road; i++){
		cin >> num1 >> num2 >> weight;

		matrice[num1][num2] = weight;
		matrice[num2][num1] = weight;
	}

	int min = 1300000000;
	int *f = new int[flour];
	for(int i = 0; i < flour; i++){
		cin >> f[i];
	}

	for(int i = 0; i < flour; i++){
		for(int j = 1; j < city + 1; j++){
			if(matrice[f[i]][j] > 0 && matrice[f[i]][j] < min) {
				int l = 1;
				int r = city;
				int m;

				while(l < r){
					m = (l + r)/2;
					if(j > f[m]){
						l = m + 1;
					}
					else if(j < f[m]){
						r = m - 1;
					}
					else{
						goto T;
					}
				}
				min = matrice[f[i]][j];
T:
int k;
			}
		}
	}

	if(min != 1300000000){
		cout << min;
	}
	else cout << "-1";
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int city, road, flour;

	cin >> city >> road >> flour;

	int **matrice = new int *[city + 1];

	for(int i = 0; i < city + 1; i++){
		matrice[i] = new int[city + 1];
	}

	for(int i = 1; i < city + 1; i++){
		for(int j = 1; j < city + 1; j++){
			if(i == j){
				matrice[i][j] = 0;
			}
			else matrice[i][j] = -1;
		}
	}
	int num1, num2, weight;
	for(int i = 0; i < road; i++){
		cin >> num1 >> num2 >> weight;

		matrice[num1][num2] = weight;
		matrice[num2][num1] = weight;
	}
	int num3;

	int min = 1300000000;
	for(int i = 0; i < flour; i++){
		cin >> num3;

		for(int j = 1; j < city + 1; j++){
			if(matrice[num3][j] > 0 && matrice[num3][j] < min) min = matrice[num3][j];
		}
	}

	if(min != 1300000000){
		cout << min;
	}
	else cout << "-1";
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int city, road, flour;

	cin >> city >> road >> flour;
	//cout << "-11" << endl;
	int **matrice = new int *[city + 1];

	for(int i = 0; i < city + 1; i++){
		matrice[i] = new int[city + 1];
	}
	//cout << "0" << endl;
	for(int i = 1; i < city + 1; i++){
		for(int j = 1; j < city + 1; j++){
			if(i == j){
				matrice[i][j] = 0;
			}
			else matrice[i][j] = -1;
		}
	}

	//cout << "1" << endl;
	int num1, num2, weight;
	for(int i = 0; i < road; i++){
		cin >> num1 >> num2 >> weight;
		if(matrice[num1][num2] > weight || matrice[num1][num2] < 0){
			matrice[num1][num2] = weight;
			matrice[num2][num1] = weight;
		}

	}
	//cout << "2" << endl;

	int min = 1300000000;
	int *f = new int[flour];
	for(int i = 0; i < flour; i++){
		cin >> f[i];
	}

	sort(f, f + flour);
	//cout << "3" << endl;

	for(int i = 0; i < flour; i++){
		for(int j = 1; j < city + 1; j++){
			if(matrice[f[i]][j] > 0 && matrice[f[i]][j] < min) {

				/*int *p = find(f, f + flour, j);
				if(p == f + flour){
					min = matrice[f[i]][j];
				}*/
				int l = 0;
				int r = flour - 1;
				int m;

				while(l < r){
					m = (l + r)/2;
					if(j > f[m]){
						l = m + 1;
					}
					else if(j < f[m]){
						r = m - 1;
					}
					else{
						goto T;
					}
				}
				min = matrice[f[i]][j];
T:
int k;
			}
		}
	}

	if(min != 1300000000){
		cout << min;
	}
	else cout << "-1";

}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int city, road, flour;

	cin >> city >> road >> flour;

	int **matrice = new int *[city + 1];

	for(int i = 0; i < city + 1; i++){
		matrice[i] = new int[city + 1];
	}

	for(int i = 1; i < city + 1; i++){
		for(int j = 1; j < city + 1; j++){
			if(i == j){
				matrice[i][j] = 0;
			}
			else matrice[i][j] = -1;
		}
	}
	int num1, num2, weight;
	for(int i = 0; i < road; i++){
		cin >> num1 >> num2 >> weight;
		if(matrice[num1][num2] > weight || matrice[num1][num2] < 0){
			matrice[num1][num2] = weight;
			matrice[num2][num1] = weight;
		}

	}

	int min = 1300000000;
	int *f = new int[flour];
	for(int i = 0; i < flour; i++){
		cin >> f[i];
	}

	for(int i = 0; i < flour; i++){
		for(int j = 1; j < city + 1; j++){
			if(matrice[f[i]][j] > 0 && matrice[f[i]][j] < min) {
/*
				int *p = find(f, f + flour, j);
				if(p == f + flour){
					min = matrice[f[i]][j];
				}*/
				int l = 0;
				int r = flour - 1;
				int m;

				while(l < r){
					m = (l + r)/2;
					if(j > f[m]){
						l = m + 1;
					}
					else if(j < f[m]){
						r = m - 1;
					}
					else{
						goto T;
					}
				}
				min = matrice[f[i]][j];
T:
int k;
			}
		}
	}

	if(min != 1300000000){
		cout << min;
	}
	else cout << "-1";
}


#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
struct Vertex
{
    int index;
    vector<Vertex*> adjacent;
   // vector<Vertex*> pred;
    vector<int> weight;
    bool isNew;
   // int d;
};
void dijkstra(vector<int> &ret,vector<Vertex*> &G,int num)
{
    vector<bool> visted;
    visted.resize(G.size());
    ret[num] = 0;
    queue<int> q;
    q.push(num);
    while (!q.empty())
    {
        int cur = q.front();
        q.pop();
        visted[cur] = true;
        for (int i = 0; i < G[cur]->adjacent.size(); i++)
        {
            if (!visted[G[cur]->adjacent[i]->index])
            {
                q.push(G[cur]->adjacent[i]->index);
                if (ret[G[cur]->adjacent[i]->index] > ret[cur] + G[cur]->weight[i])
                    ret[G[cur]->adjacent[i]->index] =   ret[cur] + G[cur]->weight[i];
            }
        }

    }

}
int main()
{
    //cout << "Hello World!" << endl;
    int n,m,k;
    vector<Vertex*> G;
    set<int> sklad;
    set<int> pek;
    cin >> n >> m >> k;
    // sklad.resize(k);
    G.resize(n);
    for (int i = 0; i < n; i++)
    {
        Vertex* v = new Vertex;
        v->index = i;
        v->isNew = false;
        G[i] = v;
        pek.insert(i);

    }
    for (int i = 0; i < m; i++)
    {
        int v1,v2,w;
        cin >> v1 >> v2 >> w;
        v1 = v1 - 1; v2 = v2 - 1;
        G[v1]->adjacent.push_back(G[v2]);
        G[v2]->adjacent.push_back(G[v1]);
        G[v1]->weight.push_back(w);
        G[v2]->weight.push_back(w);
    }
    if (k == 0 )
    {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < k; i++)
    {
        int tmp;
        cin >> tmp;
        tmp = tmp - 1;
        sklad.insert(tmp);
        pek.erase(tmp);
    }
    vector<int> ret;
    ret.resize(n);
    for (int i = 0; i < n; i++){
        ret[i] = INT_MAX;
    }
    int min = INT_MAX;//,index;
   for (auto it = pek.begin(); it != pek.end(); ++it)
   {
       dijkstra(ret,G,*it);
       for (auto itt = sklad.begin(); itt != sklad.end(); ++itt)
       {
           if (ret[*itt] < min)
           {
               min = ret[*itt];
               //index = *itt;
           }
       }
       for (int i = 0; i < n; i++){
           ret[i] = INT_MAX;
       }

   }
   if (min != INT_MAX)
    cout << min;
   else {
       cout << -1;
   }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
struct Vertex
{
    int index;
    vector<Vertex*> adjacent;
   // vector<Vertex*> pred;
    vector<long long> weight;
    bool isNew;
   // int d;
};
void dijkstra(vector<int> &ret,vector<Vertex*> &G,int num)
{
    vector<bool> visted;
    visted.resize(G.size());
    ret[num] = 0;
    queue<int> q;
    q.push(num);
    while (!q.empty())
    {
        int cur = q.front();
        q.pop();
        visted[cur] = true;
        for (int i = 0; i < G[cur]->adjacent.size(); i++)
        {
            if (!visted[G[cur]->adjacent[i]->index])
            {
                q.push(G[cur]->adjacent[i]->index);
                if (ret[G[cur]->adjacent[i]->index] > ret[cur] + G[cur]->weight[i])
                    ret[G[cur]->adjacent[i]->index] =   ret[cur] + G[cur]->weight[i];
            }
        }

    }

}
int main()
{
    //cout << "Hello World!" << endl;
    int n,m,k;
    vector<Vertex*> G;
    set<int> sklad;
    set<int> pek;
    cin >> n >> m >> k;
    // sklad.resize(k);
    G.resize(n);
    for (int i = 0; i < n; i++)
    {
        Vertex* v = new Vertex;
        v->index = i;
        v->isNew = false;
        G[i] = v;
        pek.insert(i);

    }
    for (int i = 0; i < m; i++)
    {
        int v1,v2,w;
        cin >> v1 >> v2 >> w;
        v1 = v1 - 1; v2 = v2 - 1;
        G[v1]->adjacent.push_back(G[v2]);
        G[v2]->adjacent.push_back(G[v1]);
        G[v1]->weight.push_back(w);
        G[v2]->weight.push_back(w);
    }
    if (k == 0 )
    {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < k; i++)
    {
        int tmp;
        cin >> tmp;
        tmp = tmp - 1;
        sklad.insert(tmp);
        pek.erase(tmp);
    }
    vector<int> ret;
    ret.resize(n);
    for (int i = 0; i < n; i++){
        ret[i] = LONG_MAX;
    }
    long long min = LONG_MAX;//,index;
   for (auto it = pek.begin(); it != pek.end(); ++it)
   {
       dijkstra(ret,G,*it);
       for (auto itt = sklad.begin(); itt != sklad.end(); ++itt)
       {
           if (ret[*itt] < min)
           {
               min = ret[*itt];
               //index = *itt;
           }
       }
       for (int i = 0; i < n; i++){
           ret[i] = LONG_MAX;
       }

   }
   if (min != LONG_MAX)
    cout << min;
   else {
       cout << -1;
   }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
struct Vertex
{
    int index;
    vector<Vertex*> adjacent;
    // vector<Vertex*> pred;
    vector<long long> weight;
    bool isNew;
    // int d;
};
void dijkstra(vector<int> &ret,vector<vector<long long>> G,int num,int size)
{
    vector<bool> visted;
    visted.resize(G.size());
    ret[num] = 0;
    queue<int> q;
    q.push(num);
    while (!q.empty())
    {
        int cur = q.front();
        q.pop();
        visted[cur] = true;
        for (int i = 0; i < size; i++)
        {
            if (G[cur][i] != -1){
                if (!visted[i])
                {
                    q.push(i);
                    if (ret[i] > ret[cur] + G[cur][i])
                        ret[i] = ret[cur] + G[cur][i];
                }
            }
        }

    }

}
int main()
{
    //cout << "Hello World!" << endl;
    int n,m,k;
    // vector<Vertex*> G;
    set<int> sklad;
    set<int> pek;
    cin >> n >> m >> k;
    vector<vector<long long>> G;
    G.resize(n);
    // sklad.resize(k);
    /*  G.resize(n);
    for (int i = 0; i < n; i++)
    {
        Vertex* v = new Vertex;
        v->index = i;
        v->isNew = false;
        G[i] = v;
        pek.insert(i);

    } */
    for (int i = 0; i < n; i++)
    {
        pek.insert(i);
        G[i].resize(n);
        for (int j = 0; j < n; j++)
        {
            G[i][j] = -1;
        }
    }
    for (int i = 0; i < m; i++)
    {
        int v1,v2,w;
        cin >> v1 >> v2 >> w;
        v1 = v1 - 1; v2 = v2 - 1;
        G[v1][v2] = w;
        G[v2][v1] = w;
        /* G[v1]->adjacent.push_back(G[v2]);
        G[v2]->adjacent.push_back(G[v1]);
        G[v1]->weight.push_back(w);
        G[v2]->weight.push_back(w);*/
    }
    if (k == 0 )
    {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < k; i++)
    {
        int tmp;
        cin >> tmp;
        tmp = tmp - 1;
        sklad.insert(tmp);
        pek.erase(tmp);
    }
    vector<int> ret;
    ret.resize(n);
    for (int i = 0; i < n; i++){
        ret[i] = LONG_MAX;
    }
    long long min = LONG_MAX;//,index;
    for (auto it = pek.begin(); it != pek.end(); ++it)
    {
        dijkstra(ret,G,*it,n);
        for (auto itt = sklad.begin(); itt != sklad.end(); ++itt)
        {
            if (ret[*itt] < min)
            {
                min = ret[*itt];
                //index = *itt;
            }
        }
        for (int i = 0; i < n; i++){
            ret[i] = LONG_MAX;
        }

    }
    if (min != LONG_MAX)
        cout << min;
    else {
        cout << -1;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
struct Vertex
{
    int index;
    vector<Vertex*> adjacent;
    // vector<Vertex*> pred;
    vector<long long> weight;
    bool isNew;
    // int d;
};

int main()
{
    //cout << "Hello World!" << endl;
    int n,m,k;
    vector<Vertex*> G;
    set<int> sklad;

    cin >> n >> m >> k;
    // sklad.resize(k);
    G.resize(n);
    for (int i = 0; i < n; i++)
    {
        Vertex* v = new Vertex;
        v->index = i;
        v->isNew = false;
        G[i] = v;

    }
    for (int i = 0; i < m; i++)
    {
        int v1,v2,w;
        cin >> v1 >> v2 >> w;
        v1 = v1 - 1; v2 = v2 - 1;
        G[v1]->adjacent.push_back(G[v2]);
        G[v2]->adjacent.push_back(G[v1]);
        G[v1]->weight.push_back(w);
        G[v2]->weight.push_back(w);
    }
    if (k == 0 )
    {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < k; i++)
    {
        int tmp;
        cin >> tmp;
        tmp = tmp - 1;
        sklad.insert(tmp);

    }
    vector<int> ret;
    ret.resize(n);
    for (int i = 0; i < n; i++){
        ret[i] = LONG_MAX;
    }
    long long min = LONG_MAX;//,index;
    for (auto it = sklad.begin(); it != sklad.end(); ++it)
    {
        for (int i = 0; i < G[*it]->adjacent.size(); i++)
        {
            if (sklad.count(G[*it]->adjacent[i]->index) == 0)

                if (min >  G[*it]->weight[i])
                    min =    G[*it]->weight[i];

        }

    }
    if (min != LONG_MAX)
        cout << min;
    else {
        cout << -1;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
struct Vertex
{
    int index;
    vector<Vertex*> adjacent;
    // vector<Vertex*> pred;
    vector<long long> weight;
    bool isNew;
    // int d;
};
long long dijkstra(vector<Vertex*> &G,int num,set<int> check)
{
    // vector<bool> visted;
    //visted.resize(G.size());

    // int cur = num;
    // queue<int> q;
    // q.push(num);
    /* while (!q.empty())
    {
        int cur = q.front();
        q.pop();
        visted[cur] = true;*/
    long long ret = LONG_MAX;
    for (int i = 0; i < G[num]->adjacent.size(); i++)
    {
        //  if (!visted[G[num]->adjacent[i]->index])
        //  {
        //      q.push(G[num]->adjacent[i]->index);
        if (check.count(G[num]->adjacent[i]->index))
            if (ret >  G[num]->weight[i])
                ret =    G[num]->weight[i];
        // }
    }

    //}
    return ret;

}
int main()
{
    //cout << "Hello World!" << endl;
    int n,m,k;
    vector<Vertex*> G;
    set<int> sklad;
    set<int> pek;
    cin >> n >> m >> k;
    // sklad.resize(k);
    G.resize(n);
    for (int i = 0; i < n; i++)
    {
        Vertex* v = new Vertex;
        v->index = i;
        v->isNew = false;
        G[i] = v;

    }
    for (int i = 0; i < m; i++)
    {
        int v1,v2,w;
        cin >> v1 >> v2 >> w;
        v1 = v1 - 1; v2 = v2 - 1;
        pek.insert(v1);
        pek.insert(v2);
        G[v1]->adjacent.push_back(G[v2]);
        G[v2]->adjacent.push_back(G[v1]);
        G[v1]->weight.push_back(w);
        G[v2]->weight.push_back(w);
    }
    if (k == 0 )
    {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < k; i++)
    {
        int tmp;
        cin >> tmp;
        tmp = tmp - 1;
        sklad.insert(tmp);
        pek.erase(tmp);
    }

    long long min = LONG_MAX;//,index;
    for (auto it = pek.begin(); it != pek.end(); ++it)
    {
        long long cur = dijkstra(G,*it,sklad);
        if (min > cur)
        {
            min = cur;
        }

    }
    if (min != LONG_MAX)
        cout << min;
    else {
        cout << -1;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
struct Vertex
{
    int index;
    vector<Vertex*> adjacent;
   // vector<Vertex*> pred;
    vector<long long> weight;
    bool isNew;
   // int d;
};
void dijkstra(vector<int> &ret,vector<Vertex*> &G,int num)
{
    //vector<bool> visted;
    //visted.resize(G.size());
    ret[num] = 0;
    //int cur = num;
    //queue<int> q;
    //q.push(num);
   /* while (!q.empty())
    {
        int cur = q.front();
        q.pop();
        visted[cur] = true;*/
        for (int i = 0; i < G[num]->adjacent.size(); i++)
        {

                if (ret[G[num]->adjacent[i]->index] > ret[num] + G[num]->weight[i])
                    ret[G[num]->adjacent[i]->index] =   ret[num] + G[num]->weight[i];

        }

    //}

}
int main()
{
    //cout << "Hello World!" << endl;
    int n,m,k;
    vector<Vertex*> G;
    set<int> sklad;
    set<int> pek;
    cin >> n >> m >> k;
    // sklad.resize(k);
    G.resize(n);
    for (int i = 0; i < n; i++)
    {
        Vertex* v = new Vertex;
        v->index = i;
        v->isNew = false;
        G[i] = v;

    }
    for (int i = 0; i < m; i++)
    {
        int v1,v2,w;
        cin >> v1 >> v2 >> w;
        v1 = v1 - 1; v2 = v2 - 1;
        pek.insert(v1);
        pek.insert(v2);
        G[v1]->adjacent.push_back(G[v2]);
        G[v2]->adjacent.push_back(G[v1]);
        G[v1]->weight.push_back(w);
        G[v2]->weight.push_back(w);
    }
    if (k == 0 )
    {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < k; i++)
    {
        int tmp;
        cin >> tmp;
        tmp = tmp - 1;
        sklad.insert(tmp);
        pek.erase(tmp);
    }
    vector<int> ret;
    ret.resize(n);
    for (int i = 0; i < n; i++){
        ret[i] = LONG_MAX;
    }
    long long min = LONG_MAX;//,index;
   for (auto it = pek.begin(); it != pek.end(); ++it)
   {
       dijkstra(ret,G,*it);
       for (auto itt = sklad.begin(); itt != sklad.end(); ++itt)
       {
           if (ret[*itt] < min)
           {
               min = ret[*itt];
               //index = *itt;
           }
       }
       for (int i = 0; i < n; i++){
           ret[i] = LONG_MAX;
       }

   }
   if (min != LONG_MAX)
    cout << min;
   else {
       cout << -1;
   }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
struct Vertex
{
    int index;
    vector<Vertex*> adjacent;
    // vector<Vertex*> pred;
    vector<long long> weight;
    // bool isNew;
    // int d;
};
long long dijkstra(vector<Vertex*> &G,int num,set<int> check)
{
    // vector<bool> visted;
    //visted.resize(G.size());

    // int cur = num;
    // queue<int> q;
    // q.push(num);
    /* while (!q.empty())
    {
        int cur = q.front();
        q.pop();
        visted[cur] = true;*/
    long long ret = LONG_MAX;
    for (int i = 0; i < G[num]->adjacent.size(); i++)
    {
        //  if (!visted[G[num]->adjacent[i]->index])
        //  {
        //      q.push(G[num]->adjacent[i]->index);
        if (check.count(G[num]->adjacent[i]->index))
            if (ret >  G[num]->weight[i])
                ret =    G[num]->weight[i];
        // }
    }

    //}
    return ret;

}
int main()
{
    //cout << "Hello World!" << endl;
    int n,m,k;
    vector<Vertex*> G;
    set<int> sklad;
    cin >> n >> m >> k;
    // sklad.resize(k);
    G.resize(n);
    for (int i = 0; i < n; i++)
    {
        Vertex* v = new Vertex;
        v->index = i;
        // v->isNew = false;
        G[i] = v;

    }
    for (int i = 0; i < m; i++)
    {
        int v1,v2,w;
        cin >> v1 >> v2 >> w;
        v1 = v1 - 1; v2 = v2 - 1;
        G[v1]->adjacent.push_back(G[v2]);
        G[v2]->adjacent.push_back(G[v1]);
        G[v1]->weight.push_back(w);
        G[v2]->weight.push_back(w);
    }
    if (k == 0 )
    {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < k; i++)
    {
        int tmp;
        cin >> tmp;
        tmp = tmp - 1;
        sklad.insert(tmp);

    }

    long long min = LONG_MAX;//,index;
    for (int i = 0; i < n; i++)
    {   if (sklad.count(i) == 0){
            long long cur = dijkstra(G,i,sklad);
            if (min > cur)
            {
                min = cur;
            }
        }

    }
    if (min != LONG_MAX)
        cout << min;
    else {
        cout << -1;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
struct Vertex
{
    int index;
    vector<Vertex*> adjacent;
   // vector<Vertex*> pred;
    vector<long long> weight;
    bool isNew;
   // int d;
};
void dijkstra(vector<int> &ret,vector<Vertex*> &G,int num)
{
    vector<bool> visted;
    visted.resize(G.size());
    ret[num] = 0;
    int cur = num;
    queue<int> q;
    q.push(num);
   /* while (!q.empty())
    {
        int cur = q.front();
        q.pop();
        visted[cur] = true;*/
        for (int i = 0; i < G[cur]->adjacent.size(); i++)
        {
            if (!visted[G[cur]->adjacent[i]->index])
            {
                q.push(G[cur]->adjacent[i]->index);
                if (ret[G[cur]->adjacent[i]->index] > ret[cur] + G[cur]->weight[i])
                    ret[G[cur]->adjacent[i]->index] =   ret[cur] + G[cur]->weight[i];
            }
        }

    //}

}
int main()
{
    //cout << "Hello World!" << endl;
    int n,m,k;
    vector<Vertex*> G;
    set<int> sklad;
    set<int> pek;
    cin >> n >> m >> k;
    // sklad.resize(k);
    G.resize(n);
    for (int i = 0; i < n; i++)
    {
        Vertex* v = new Vertex;
        v->index = i;
        v->isNew = false;
        G[i] = v;

    }
    for (int i = 0; i < m; i++)
    {
        int v1,v2,w;
        cin >> v1 >> v2 >> w;
        v1 = v1 - 1; v2 = v2 - 1;
        pek.insert(v1);
        pek.insert(v2);
        G[v1]->adjacent.push_back(G[v2]);
        G[v2]->adjacent.push_back(G[v1]);
        G[v1]->weight.push_back(w);
        G[v2]->weight.push_back(w);
    }
    if (k == 0 )
    {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < k; i++)
    {
        int tmp;
        cin >> tmp;
        tmp = tmp - 1;
        sklad.insert(tmp);
        pek.erase(tmp);
    }
    vector<int> ret;
    ret.resize(n);
    for (int i = 0; i < n; i++){
        ret[i] = LONG_MAX;
    }
    long long min = LONG_MAX;//,index;
   for (auto it = pek.begin(); it != pek.end(); ++it)
   {
       dijkstra(ret,G,*it);
       for (auto itt = sklad.begin(); itt != sklad.end(); ++itt)
       {
           if (ret[*itt] < min)
           {
               min = ret[*itt];
               //index = *itt;
           }
       }
       for (int i = 0; i < n; i++){
           ret[i] = LONG_MAX;
       }

   }
   if (min != LONG_MAX)
    cout << min;
   else {
       cout << -1;
   }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
struct Vertex
{
    int index;
    vector<Vertex*> adjacent;
   // vector<Vertex*> pred;
    vector<long long> weight;
    bool isNew;
   // int d;
};
void dijkstra(vector<int> &ret,vector<Vertex*> &G,int num)
{
    vector<bool> visted;
    visted.resize(G.size());
    ret[num] = 0;
    queue<int> q;
    q.push(num);
    while (!q.empty())
    {
        int cur = q.front();
        q.pop();
        visted[cur] = true;
        for (int i = 0; i < G[cur]->adjacent.size(); i++)
        {
            if (!visted[G[cur]->adjacent[i]->index])
            {
                q.push(G[cur]->adjacent[i]->index);
                if (ret[G[cur]->adjacent[i]->index] > ret[cur] + G[cur]->weight[i])
                    ret[G[cur]->adjacent[i]->index] =   ret[cur] + G[cur]->weight[i];
            }
        }

    }

}
int main()
{
    //cout << "Hello World!" << endl;
    int n,m,k;
    vector<Vertex*> G;
    set<int> sklad;
    set<int> pek;
    cin >> n >> m >> k;
    // sklad.resize(k);
    G.resize(n);
    for (int i = 0; i < n; i++)
    {
        Vertex* v = new Vertex;
        v->index = i;
        v->isNew = false;
        G[i] = v;

    }
    for (int i = 0; i < m; i++)
    {
        int v1,v2,w;
        cin >> v1 >> v2 >> w;
        v1 = v1 - 1; v2 = v2 - 1;
        pek.insert(v1);
        pek.insert(v2);
        G[v1]->adjacent.push_back(G[v2]);
        G[v2]->adjacent.push_back(G[v1]);
        G[v1]->weight.push_back(w);
        G[v2]->weight.push_back(w);
    }
    if (k == 0 )
    {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < k; i++)
    {
        int tmp;
        cin >> tmp;
        tmp = tmp - 1;
        sklad.insert(tmp);
        pek.erase(tmp);
    }
    vector<int> ret;
    ret.resize(n);
    for (int i = 0; i < n; i++){
        ret[i] = LONG_MAX;
    }
    long long min = LONG_MAX;//,index;
   for (auto it = pek.begin(); it != pek.end(); ++it)
   {
       dijkstra(ret,G,*it);
       for (auto itt = sklad.begin(); itt != sklad.end(); ++itt)
       {
           if (ret[*itt] < min)
           {
               min = ret[*itt];
               //index = *itt;
           }
       }
       for (int i = 0; i < n; i++){
           ret[i] = LONG_MAX;
       }

   }
   if (min != LONG_MAX)
    cout << min;
   else {
       cout << -1;
   }

    return 0;
}


#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
#define ll long long int
#define maxn 200008
typedef pair<int,int>pii;
const int inf=1e9+7;;
struct Edge{
    int to,dist,next;
}edges[maxn];
int n;
int a[maxn];
int hd[maxn],tot;
bool vis[maxn];
void addedge(int from,int to,int dist)
{
    edges[++tot].dist=dist;
    edges[tot].next=hd[from];
    edges[tot].to=to;
    hd[from]=tot;
}
int main()
{
    int m,k;
    int u,v,c,ans;
    tot=0;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<m;i++)
    {
          scanf("%d%d%d",&u,&v,&c);
          addedge(u,v,c);
          addedge(v,u,c);
    }
    ans=inf;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]=1;
    }
    for(int i=0;i<k;i++)
    {
       for(int t=hd[a[i]];t;t=edges[t].next)
       {
           if(!t) continue;
           if(vis[edges[t].to]==0)
           {
               ans=min(ans,edges[t].dist);
           }
       }
    }
    if(ans==inf) printf("-1\n");
    else printf("%d\n",ans);

}


#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
#define ll long long int
#define maxn 120008
const int inf=1e9+8;;
struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};
int n;
int a[maxn];
vector<Edge>edges;
vector<int>G[maxn];
bool vis[maxn];
void init()
{
    for(int i=0;i<=1e5+3;i++) G[i].clear();
    edges.clear();
    memset(vis,0,sizeof vis);
}
void addedge(int from,int to,int dist)
{
    edges.push_back(Edge(from,to,dist));
    int m=edges.size();
    G[from].push_back(m-1);
}
int main()
{
    int mm,k;
    int u,v,c,ans;
    init();
    scanf("%d%d%d",&n,&mm,&k);
    for(int i=0;i<mm;i++)
    {
          scanf("%d%d%d",&u,&v,&c);
          addedge(u,v,c);
          addedge(v,u,c);
    }
    ans=inf;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]=1;
    }
    for(int i=0;i<k;i++)
    {
        for(int kk=0;kk<G[a[i]].size();kk++)
        {
            int st=G[a[i]][kk];
            if(vis[st]==0)
            {
                ans=min(ans,edges[st].dist);
            }
        }
    }
    if(ans==inf) printf("-1\n");
    else printf("%d\n",ans);

}


#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
#define ll long long int
#define maxn 110008
const int inf=1e9+8;;
struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};
int n;
int a[maxn];
vector<Edge>edges;
vector<int>G[maxn];
bool vis[maxn];
void init()
{
    for(int i=0;i<=n+2;i++) G[i].clear();
    edges.clear();
    memset(vis,0,sizeof vis);
}
void addedge(int from,int to,int dist)
{
    edges.push_back(Edge(from,to,dist));
    int m=edges.size();
    G[from].push_back(m-1);
}
int main()
{
    int m,k;
    int u,v,c,ans;
    init();
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<m;i++)
    {
          scanf("%d%d%d",&u,&v,&c);
          addedge(u,v,c);
          addedge(v,u,c);
    }
    ans=inf;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]=1;
    }
    for(int i=0;i<k;i++)
    {
        for(int kk=0;kk<G[a[i]].size();kk++)
        {
            int st=G[a[i]][kk];
            if(vis[st]==0)
            {
                ans=min(ans,edges[st].dist);
            }
        }
    }
    if(ans==inf) printf("-1\n");
    else printf("%d\n",ans);

}


#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
#define ll long long int
#define maxn 100008
typedef pair<int,int>pii;
const int inf=1e9+7;;
struct Edge{
    int to,dist,next;
}edges[maxn];
int n;
int a[maxn];
int hd[maxn],tot;
bool vis[maxn];
void addedge(int from,int to,int dist)
{
    edges[++tot].dist=dist;
    edges[tot].next=hd[from];
    edges[tot].to=to;
    hd[from]=tot;
}
int main()
{
    int m,k;
    int u,v,c,ans;
    tot=0;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<m;i++)
    {
          scanf("%d%d%d",&u,&v,&c);
          addedge(u,v,c);
          addedge(v,u,c);
    }
    ans=inf;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]=1;
    }
    for(int i=0;i<k;i++)
    {
       for(int t=hd[a[i]];t;t=edges[t].next)
       {
           if(!t) continue;
           if(vis[edges[t].to]==0)
           {
               ans=min(ans,edges[t].dist);
           }
       }
    }
    if(ans==inf) printf("-1\n");
    else printf("%d\n",ans);

}


#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
#define ll __int64
#define maxn 1020008
const ll inf=1e13+8;;
struct Edge{
    ll from,to,dist;
    Edge(ll u,ll v,ll d):from(u),to(v),dist(d){}
};
ll n;
ll a[maxn];
vector<Edge>edges;
vector<ll>G[maxn];
int vis[maxn];
void init()
{
    for(ll i=0;i<=n+2;i++) G[i].clear();
    edges.clear();
    memset(vis,0,sizeof vis);
}
void addedge(ll from,ll to,ll dist)
{
    edges.push_back(Edge(from,to,dist));
    ll m=edges.size();
    G[from].push_back(m-1);
}
int main()
{
    ll mm,k;
    ll u,v,c,ans;
    scanf("%I64d%I64d%I64d",&n,&mm,&k);
    init();
    for(ll i=0;i<mm;i++)
    {
          scanf("%I64d%I64d%I64d",&u,&v,&c);
          addedge(u,v,c);
          addedge(v,u,c);
    }
    ans=inf;
    for(ll i=0;i<k;i++)
    {
        scanf("%I64d",&a[i]);
        vis[a[i]]=1;
    }
    for(ll i=0;i<k;i++)
    {
        for(ll kk=0;kk<G[a[i]].size();kk++)
        {
            ll st=G[a[i]][kk];
            if(vis[st]==0&&ans>edges[st].dist)
            {
                ans=edges[st].dist;
            }
        }
    }
    if(ans==inf) printf("-1\n");
    else printf("%I64d\n",ans);

}


#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
#define ll long long int
#define maxn 100008
typedef pair<int,int>pii;
const int inf=1e9+7;;
struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};
int n;
int a[maxn];
vector<Edge>edges;
vector<int>G[maxn];
bool vis[maxn];
void init()
{
    for(int i=0;i<n;i++) G[i].clear();
    edges.clear();
}
void addedge(int from,int to,int dist)
{
    edges.push_back(Edge(from,to,dist));
    int m=edges.size();
    G[from].push_back(m-1);
}
int main()
{
    int n,m,k;
    int u,v,c,ans;
    init();
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<m;i++)
    {
          scanf("%d%d%d",&u,&v,&c);
          addedge(u,v,c);
          addedge(v,u,c);
    }
    ans=inf;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]=1;
    }
    for(int i=0;i<n;i++)
    {
        for(int k=0;k<G[a[i]].size();k++)
        {
            int st=G[a[i]][k];
            if(vis[st]==0)
            {
                ans=min(ans,edges[st].dist);
            }
        }
    }
    if(ans==inf) printf("-1\n");
    else printf("%d\n",ans);

}


#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
#define ll long long int
#define maxn 100008
typedef pair<int,int>pii;
const int inf=1e9+8;;
struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};
int n;
int a[maxn];
vector<Edge>edges;
vector<int>G[maxn];
bool vis[maxn];
void init()
{
    for(int i=0;i<=n+2;i++) G[i].clear();
    edges.clear();
    memset(vis,0,sizeof vis);
}
void addedge(int from,int to,int dist)
{
    edges.push_back(Edge(from,to,dist));
    int m=edges.size();
    G[from].push_back(m-1);
}
int main()
{
    int n,m,k;
    int u,v,c,ans;
    init();
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<m;i++)
    {
          scanf("%d%d%d",&u,&v,&c);
          addedge(u,v,c);
          addedge(v,u,c);
    }
    ans=inf;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]=1;
    }
    for(int i=0;i<k;i++)
    {
        for(int kk=0;kk<G[a[i]].size();kk++)
        {
            int st=G[a[i]][kk];
            if(vis[st]==0)
            {
                ans=min(ans,edges[st].dist);
            }
        }
    }
    if(ans==inf) printf("-1\n");
    else printf("%d\n",ans);

}


#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
#define ll __int64
#define maxn 1020008
const ll inf=1e13+8;;
struct Edge{
    ll from,to,dist;
    Edge(ll u,ll v,ll d):from(u),to(v),dist(d){}
};
ll n;
ll a[maxn];
vector<Edge>edges;
vector<ll>G[maxn];
int vis[maxn];
void init()
{
    for(ll i=0;i<=n+2;i++) G[i].clear();
    edges.clear();
    memset(vis,0,sizeof vis);
}
void addedge(ll from,ll to,ll dist)
{
    edges.push_back(Edge(from,to,dist));
    ll m=edges.size();
    G[from].push_back(m-1);
}
int main()
{
    ll mm,k;
    ll u,v,c,ans;
    scanf("%I64d%I64d%I64d",&n,&mm,&k);
    init();
    for(ll i=0;i<mm;i++)
    {
          scanf("%I64d%I64d%I64d",&u,&v,&c);
          addedge(u,v,c);
          addedge(v,u,c);
    }
    ans=inf;
    for(ll i=0;i<k;i++)
    {
        scanf("%I64d",&a[i]);
        vis[a[i]]=1;
    }
    for(ll i=1;i<=n;i++)
    {
        if(vis[i])
        {
                for(ll kk=0;kk<G[i].size();kk++)
            {
                ll st=G[i][kk];
                if(vis[edges[st].to]==0&&ans>edges[st].dist)
                {
                    ans=edges[st].dist;
                }
            }
        }

    }
    if(ans==inf) printf("-1\n");
    else printf("%I64d\n",ans);

}


#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
#define ll long long int
#define maxn 100008
typedef pair<int,int>pii;
const int inf=1e9+7;;
struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};
int n;
int a[maxn];
vector<Edge>edges;
vector<int>G[maxn];
bool vis[maxn];
void init()
{
    for(int i=0;i<n;i++) G[i].clear();
    edges.clear();
}
void addedge(int from,int to,int dist)
{
    edges.push_back(Edge(from,to,dist));
    int m=edges.size();
    G[from].push_back(m-1);
}
int main()
{
    int m,k;
    int u,v,c,ans;

    scanf("%d%d%d",&n,&m,&k);
    init();
    for(int i=0;i<m;i++)
    {
          scanf("%d%d%d",&u,&v,&c);
          addedge(u,v,c);
          addedge(v,u,c);
    }
    ans=inf;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]=1;
    }
    for(int i=0;i<k;i++)
    {
        for(int kk=0;kk<G[a[i]].size();kk++)
        {
            int st=G[a[i]][kk];
            if(vis[edges[st].to]==0)
            {
                ans=min(ans,edges[st].dist);
            }
        }
    }
    if(ans==inf) printf("-1\n");
    else printf("%d\n",ans);

}


#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
#define ll __int64
#define maxn 220008
const ll inf=1e13+8;;
struct Edge{
    ll from,to,dist;
    Edge(ll u,ll v,ll d):from(u),to(v),dist(d){}
};
ll n;
ll a[maxn];
vector<Edge>edges;
vector<ll>G[maxn];
bool vis[maxn];
void init()
{
    for(ll i=0;i<=n+2;i++) G[i].clear();
    edges.clear();
    memset(vis,0,sizeof vis);
}
void addedge(ll from,ll to,ll dist)
{
    edges.push_back(Edge(from,to,dist));
    ll m=edges.size();
    G[from].push_back(m-1);
}
int main()
{
    ll mm,k;
    ll u,v,c,ans;
    scanf("%I64d%I64d%I64d",&n,&mm,&k);
    init();
    for(ll i=0;i<mm;i++)
    {
          scanf("%I64d%I64d%I64d",&u,&v,&c);
          addedge(u,v,c);
          addedge(v,u,c);
    }
    ans=inf;
    for(ll i=0;i<k;i++)
    {
        scanf("%I64d",&a[i]);
        vis[a[i]]=1;
    }
    for(ll i=0;i<k;i++)
    {
        for(ll kk=0;kk<G[a[i]].size();kk++)
        {
            ll st=G[a[i]][kk];
            if(vis[st]==0)
            {
                ans=min(ans,edges[st].dist);
            }
        }
    }
    if(ans==inf) printf("-1\n");
    else printf("%I64d\n",ans);

}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2*m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		map[i * 2][0] = t1;
		map[i * 2][1] = t2;
		map[i * 2][2] = l;

		map[i * 2 + 1][0] = t2;
		map[i * 2 + 1][1] = t1;
		map[i * 2 + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, result = 1000000001;

	vector<bool> isf;
	for (i = 0; i < n; ++i)
	{
		if (isflour(flour, i)) isf.push_back(true);
		else isf.push_back(false);
	}
	for (i = 0; i < k; ++i)
	{
		for (j = 0; j < 2*m; ++j)
		{
			if (isf[map[j][0]])
			{
				if (!isf[map[j][1]])
				{
					if (result > map[j][2])
					{
						result = map[j][2];
					}
				}
			}
		}
	}
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(n, -1);
	vector<vector<ll> > map(n, TEMPLATE);
	delete &TEMPLATE;
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;
		if (map[t1][t2] > l || map[t1][t2] == -1)
		{
			map[t1][t2] = l;
			map[t2][t1] = l;
		}
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, m = 1000000001;
	for (i = 0; i < flour.size(); ++i)
	{
		for (j = 0; j < map[flour[i]].size(); ++j)
		{
			if (map[flour[i]][j] != -1 && map[flour[i]][j] < m && !isflour(flour, j))
			{
				m = map[flour[i]][j];
			}
		}
	}
	ll result = m;
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#define ll long long
#define pause system("pause")
using namespace std;

ll search(vector<vector<ll> > &map, vector<ll> &flour, ll n)
{
	ll i, j, m = 1000000001;
	for (i = 0; i < flour.size(); ++i)
	{
		for (j = 0; j < n; ++j)
		{
			if (map[flour[i]][j] != -1 && map[flour[i]][j] < m)
			{
				m = map[flour[i]][j];
			}
		}
	}
	return m;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(n, -1);
	vector<vector<ll> > map(n, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;
		if (map[t1][t2] > l || map[t1][t2] == -1)
		{
			map[t1][t2] = l;
			map[t2][t1] = l;
		}
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT

	ll result = search(map, flour, n);
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			flour.erase(flour.begin() + i);
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
	const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2 * m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii][0] = t1;
		map[ii][1] = t2;
		map[ii][2] = l;

		map[ii + 1][0] = t2;
		map[ii + 1][1] = t1;
		map[ii + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f - 1);
	}

	//END INPUT
	ll j, result = 1000000001;

	vector<bool> isf;
	sort(flour.begin(), flour.end());
	for (i = 0; i < n; ++i)
	{
		if (isflour(flour, i)) isf.push_back(true);
		else isf.push_back(false);
	}
	i = 0;
	while (i < map.size())
	{
		if (!(isf[map[i][0]] && !isf[map[i][1]]) || (isf[map[i][0]] == isf[map[i][1]]))
			map.erase(map.begin() + i);
		else
		{
			result = (result > map[i][2]) ? map[i][2] : result;
			i++;
		}
	}

	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
	for (ll j = 0; j < n; ++j)
	cout << map[i][j];
	cout << endl;
	}*/
	return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}
ll search(vector<vector<ll> > &map, vector<ll> &flour, ll &n)
{
	ll i, j, m = 1000000001;
	for (i = 0; i < flour.size(); ++i)
	{
		for (j = 0; j < n; ++j)
		{
			if (map[flour[i]][j] != -1 && map[flour[i]][j] < m && !isflour(flour, j))
			{
				m = map[flour[i]][j];
			}
		}
	}
	return m;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(n, -1);
	vector<vector<ll> > map(n, TEMPLATE);
	delete &TEMPLATE;
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;
		if (map[t1][t2] > l || map[t1][t2] == -1)
		{
			map[t1][t2] = l;
			map[t2][t1] = l;
		}
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT

	ll result = search(map, flour, n);
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			flour.erase(flour.begin() + i);
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2*m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii][0] = t1;
		map[ii][1] = t2;
		map[ii][2] = l;

		map[ii + 1][0] = t2;
		map[ii + 1][1] = t1;
		map[ii + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, result = 1000000001;

	vector<bool> isf;

	for (i = 0; i < n; ++i)
	{
		if (isflour(flour, i)) isf.push_back(true);
		else isf.push_back(false);
	}
	i = 0;
	while(i < map.size())
	{
		if (!(isf[map[i][0]] && !isf[map[i][1]]) || (isf[map[i][0]] == isf[map[i][1]]))
			map.erase(map.begin() + i);
		else
		{
			result = (result > map[i][2]) ? map[i][2] : result;
			i++;
		}
	}

	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2*m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		map[i * 2][0] = t1;
		map[i * 2][1] = t2;
		map[i * 2][2] = l;

		map[i * 2 + 1][0] = t2;
		map[i * 2 + 1][1] = t1;
		map[i * 2 + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, result = 1000000001;
	for (i = 0; i < k; ++i)
	{
		for (j = 0; j < 2*n; ++j)
		{
			if (isflour(flour, map[j][0]))
			{
				if (!isflour(flour, map[j][1]))
				{
					if (result > map[j][2])
					{
						result = map[j][2];
					}
				}
			}
		}
	}
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll int
#define pause system("pause")
using namespace std;

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;

	vector<vector<ll> > map(2 * m);

	vector<ll> flour;

	vector<bool> isf(n);

	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii].push_back(t1);
		map[ii].push_back(t2);
		map[ii].push_back(l);

		map[ii + 1].push_back(t2);
		map[ii + 1].push_back(t1);
		map[ii + 1].push_back(l);
	}
	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f - 1);
	}

	//END INPUT
	ll result = 1000000001;

	for (i = 0; i < k; ++i)
		isf[flour[i]] = true;

	for (i = 0; i < m*2; ++i)
		if (isf[map[i][0]] && !isf[map[i][1]])
			result = (result > map[i][2]) ? map[i][2] : result;

	if (result < 1000000001) cout << result;
	else cout << -1;
	return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> flour, ll current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}
ll search(vector<vector<ll> > &map, vector<ll> &flour, ll n)
{
	ll i, j, m = 1000000001;
	for (i = 0; i < flour.size(); ++i)
	{
		for (j = 0; j < n; ++j)
		{
			if (map[flour[i]][j] != -1 && map[flour[i]][j] < m && !isflour(flour, j))
			{
				m = map[flour[i]][j];
			}
		}
	}
	return m;
}

int main()
{
	//
	//
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(n, -1);
	vector<vector<ll> > map(n, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;
		if (map[t1][t2] > l || map[t1][t2] == -1)
		{
			map[t1][t2] = l;
			map[t2][t1] = l;
		}
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT

	ll result = search(map, flour, n);
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			flour.erase(flour.begin() + i);
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2*m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii][0] = t1;
		map[ii][1] = t2;
		map[ii][2] = l;

		map[ii + 1][0] = t2;
		map[ii + 1][1] = t1;
		map[ii + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, result = 1000000001;

	vector<bool> isf;

	for (i = 0; i < n; ++i)
	{
		if (isflour(flour, i)) isf.push_back(true);
		else isf.push_back(false);
	}
	i = 0;
	while(i < map.size())
	{
		if (!(isf[map[i][0]] && !isf[map[i][1]]) || (isf[map[i][0]] == isf[map[i][1]]))
			map.erase(map.begin() + i);
		else
			i++;
	}

	for (j = 0; j < map.size(); ++j)
	{
		result = (result > map[j][2]) ? map[j][2] : result;
	}
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll int
#define pause system("pause")
using namespace std;

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;

	vector<vector<ll> > map(2 * m);

	vector<ll> flour;

	vector<bool> isf(n);

	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii].push_back(t1);
		map[ii].push_back(t2);
		map[ii].push_back(l);

		map[ii + 1].push_back(t2);
		map[ii + 1].push_back(t1);
		map[ii + 1].push_back(l);
	}
	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f - 1);
	}

	//END INPUT
	ll result = 1000000001;

	for (i = 0; i < k; ++i)
		isf[flour[i]] = true;

	for (i = 0; i < m; ++i)
		if (isf[map[i][0]])
			result = (result > map[i][2]) ? map[i][2] : result;

	if (result < 1000000001) cout << result;
	else cout << -1;
	return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2*m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		map[i * 2][0] = t1;
		map[i * 2][1] = t2;
		map[i * 2][2] = l;

		map[i * 2 + 1][0] = t2;
		map[i * 2 + 1][1] = t1;
		map[i * 2 + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, result = 1000000001;

	vector<bool> isf;

	for (i = 0; i < n; ++i)
	{
		if (isflour(flour, i)) isf.push_back(true);
		else isf.push_back(false);
	}
	i = 0;
	while(i < map.size())
	{
		if (!(isf[map[i][0]] && !isf[map[i][1]]) || (isf[map[i][0]] == isf[map[i][1]]))
			map.erase(map.begin() + i);
		else
			i++;
	}

	for (i = 0; i < k; ++i)
	{
		for (j = 0; j < map.size(); ++j)
		{
			if (result > map[j][2])
			{
				result = map[j][2];
			}
		}
	}
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll int
#define pause system("pause")
using namespace std;

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;

	vector<vector<ll> > map(2 * m);

	vector<ll> flour;

	vector<bool> isf(n);

	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii].push_back(t1);
		map[ii].push_back(t2);
		map[ii].push_back(l);

		map[ii + 1].push_back(t2);
		map[ii + 1].push_back(t1);
		map[ii + 1].push_back(l);
	}
	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f - 1);
	}

	//END INPUT
	ll result = 1000000001;

	for (i = 0; i < k; ++i)
		isf[flour[i]] = true;

	for (i = 0; i < m*2; ++i)
		if (isf[map[i][0]])
			result = (result > map[i][2]) ? map[i][2] : result;

	if (result < 1000000001) cout << result;
	else cout << -1;
	return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2*m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		map[i * 2][0] = t1;
		map[i * 2][1] = t2;
		map[i * 2][2] = l;

		map[i * 2 + 1][0] = t2;
		map[i * 2 + 1][1] = t1;
		map[i * 2 + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, result = 1000000001;

	vector<bool> isf;

	for (i = 0; i < n; ++i)
	{
		if (isflour(flour, i)) isf.push_back(true);
		else isf.push_back(false);
	}
	i = 0;
	while(i < map.size())
	{
		if (!(isf[map[i][0]] && !isf[map[i][1]]) || (isf[map[i][0]] && isf[map[i][1]]) ||
			(!isf[map[i][0]] && !isf[map[i][1]]))
		{
			map.erase(map.begin() + i);
		}
		else
			i++;
	}

	for (i = 0; i < k; ++i)
	{
		for (j = 0; j < map.size(); ++j)
		{
			if (result > map[j][2])
			{
				result = map[j][2];
			}
		}
	}
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	ll j = flour.size();
	for (i = 0; i < j; ++i)
	{
		if (current == flour[i])
		{
			flour.erase(flour.begin() + i);
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2*m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii][0] = t1;
		map[ii][1] = t2;
		map[ii][2] = l;

		map[ii + 1][0] = t2;
		map[ii + 1][1] = t1;
		map[ii + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, result = 1000000001;

	vector<bool> isf;

	sort(flour.begin(), flour.end());

	for (i = 0; i < n; ++i)
	{
		if (isflour(flour, i)) isf.push_back(true);
		else isf.push_back(false);
	}
	i = 0;
	while(i < m)
	{
		if (!(!(isf[map[i][0]] && !isf[map[i][1]]) || (isf[map[i][0]] == isf[map[i][1]])))
			result = (result > map[i][2]) ? map[i][2] : result;
		i++;
	}

	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll int
#define pause system("pause")
using namespace std;
ll iter = 0;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = iter; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			iter = i - 1;
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
	const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2 * m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii][0] = t1;
		map[ii][1] = t2;
		map[ii][2] = l;

		map[ii + 1][0] = t2;
		map[ii + 1][1] = t1;
		map[ii + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f - 1);
	}

	//END INPUT
	ll j, result = 1000000001;

	sort(flour.begin(), flour.end());

	vector<bool> isf;
	for (i = 0; i < n; ++i)
	{
		if (isflour(flour, i)) isf.push_back(true);
		else isf.push_back(false);
	}
	i = 0;
	while (i < map.size())
	{
		if (!(isf[map[i][0]] && !isf[map[i][1]]) || (isf[map[i][0]] == isf[map[i][1]]))
			map.erase(map.begin() + i);
		else
		{
			result = (result > map[i][2]) ? map[i][2] : result;
			i++;
		}
	}

	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
	for (ll j = 0; j < n; ++j)
	cout << map[i][j];
	cout << endl;
	}*/
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll int
#define pause system("pause")
using namespace std;

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
	const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2 * m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii][0] = t1;
		map[ii][1] = t2;
		map[ii][2] = l;

		map[ii + 1][0] = t2;
		map[ii + 1][1] = t1;
		map[ii + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f - 1);
	}

	//END INPUT
	ll result = 1000000001;

	vector<bool> isf(n);

	for (i = 0; i < k; ++i)
		isf[flour[i]] = true;

	for (i = 0; i < m; ++i)
		if (isf[map[i][0]])
			result = (result > map[i][2]) ? map[i][2] : result;

	if (result < 1000000001) cout << result;
	else cout << -1;
	return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2*m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		map[i * 2][0] = t1;
		map[i * 2][1] = t2;
		map[i * 2][2] = l;

		map[i * 2 + 1][0] = t2;
		map[i * 2 + 1][1] = t1;
		map[i * 2 + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, result = 1000000001;
	for (i = 0; i < k; ++i)
	{
		for (j = 0; j < 2*m; ++j)
		{
			if (isflour(flour, map[j][0]))
			{
				if (!isflour(flour, map[j][1]))
				{
					if (result > map[j][2])
					{
						result = map[j][2];
					}
				}
			}
		}
	}
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(n, -1);
	vector<vector<ll> > map(n, TEMPLATE);
	delete &TEMPLATE;
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;
		if (map[t1][t2] > l || map[t1][t2] == -1)
		{
			map[t1][t2] = l;
			map[t2][t1] = l;
		}
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j;
	m = 1000000001;
	for (i = 0; i < flour.size(); ++i)
	{
		for (j = 0; j < map[flour[i]].size(); ++j)
		{
			if (map[flour[i]][j] != -1 && map[flour[i]][j] < m && !isflour(flour, j))
			{
				m = map[flour[i]][j];
			}
		}
	}
	ll result = m;
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2*n, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		map[i * 2][0] = t1;
		map[i * 2][1] = t2;
		map[i * 2][2] = l;

		map[i * 2 + 1][0] = t2;
		map[i * 2 + 1][1] = t1;
		map[i * 2 + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, result = 1000000001;
	for (i = 0; i < k; ++i)
	{
		for (j = 0; j < 2*n; ++j)
		{
			if (isflour(flour, map[j][0]))
			{
				if (!isflour(flour, map[j][1]))
				{
					if (result > map[j][2])
					{
						result = map[j][2];
					}
				}
			}
		}
	}
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#define ll long long
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> flour, ll current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}
ll search(vector<vector<ll> > &map, vector<ll> &flour, ll n)
{
	ll i, j, m = 1000000001;
	for (i = 0; i < flour.size(); ++i)
	{
		for (j = 0; j < n; ++j)
		{
			if (map[flour[i]][j] != -1 && map[flour[i]][j] < m && !isflour(flour, j))
			{
				m = map[flour[i]][j];
			}
		}
	}
	return m;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(n, -1);
	vector<vector<ll> > map(n, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;
		if (map[t1][t2] > l || map[t1][t2] == -1)
		{
			map[t1][t2] = l;
			map[t2][t1] = l;
		}
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT

	ll result = search(map, flour, n);
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			flour.erase(flour.begin() + i);
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
	const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2 * m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii][0] = t1;
		map[ii][1] = t2;
		map[ii][2] = l;

		map[ii + 1][0] = t2;
		map[ii + 1][1] = t1;
		map[ii + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f - 1);
	}

	//END INPUT
	ll j, result = 1000000001;

	vector<bool> isf(n, false);
	for (i = 0; i < k; ++i)
		isf[flour[i]] = true;
	i = 0;
	while (i < map.size())
	{
		if (!(isf[map[i][0]] && !isf[map[i][1]]) || (isf[map[i][0]] == isf[map[i][1]]))
			map.erase(map.begin() + i);
		else
		{
			result = (result > map[i][2]) ? map[i][2] : result;
			i++;
		}
	}

	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
	for (ll j = 0; j < n; ++j)
	cout << map[i][j];
	cout << endl;
	}*/
	return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = 0; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
const vector<ll> TEMPLATE(n, -1);
	vector<vector<ll> > map(n, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;
		if (map[t1][t2] > l || map[t1][t2] == -1)
		{
			map[t1][t2] = l;
			map[t2][t1] = l;
		}
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f-1);
	}

	//END INPUT
	ll j, result = 1000000001;
	for (i = 0; i < k; ++i)
	{
		for (j = 0; j < n; ++j)
		{
			if (map[flour[i]][j] != -1 && map[flour[i]][j] < result && !isflour(flour, j))
			{
				result = map[flour[i]][j];
			}
		}
	}
	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
		for (ll j = 0; j < n; ++j)
			cout << map[i][j];
		cout << endl;
	}*/
    return 0;
}


#include <iostream>
#include <vector>
#define ll int
#define pause system("pause")
using namespace std;
ll iter = 0;
bool isflour(vector<ll> &flour, ll &current)
{
	ll i;
	for (i = iter; i < flour.size(); ++i)
	{
		if (current == flour[i])
		{
			iter = i - 1;
			return true;
		}
	}
	return false;
}

int main()
{
	ll n, m, k, i;
	cin >> n >> m >> k;
	const vector<ll> TEMPLATE(3);
	vector<vector<ll> > map(2 * m, TEMPLATE);
	vector<ll> flour;
	for (i = 0; i < m; ++i)
	{
		ll t1, t2, l;
		cin >> t1 >> t2 >> l;
		t1--; t2--;

		ll ii = i * 2;
		map[ii][0] = t1;
		map[ii][1] = t2;
		map[ii][2] = l;

		map[ii + 1][0] = t2;
		map[ii + 1][1] = t1;
		map[ii + 1][2] = l;
	}

	for (i = 0; i < k; ++i)
	{
		int f;
		cin >> f;
		flour.push_back(f - 1);
	}

	//END INPUT
	ll j, result = 1000000001;

	vector<bool> isf;
	for (i = 0; i < n; ++i)
	{
		if (isflour(flour, i)) isf.push_back(true);
		else isf.push_back(false);
	}
	i = 0;
	while (i < map.size())
	{
		if (!(isf[map[i][0]] && !isf[map[i][1]]) || (isf[map[i][0]] == isf[map[i][1]]))
			map.erase(map.begin() + i);
		else
		{
			result = (result > map[i][2]) ? map[i][2] : result;
			i++;
		}
	}

	if (result < 1000000001) cout << result;
	else cout << -1;

	/*for (i = 0; i < n; ++i)
	{
	for (ll j = 0; j < n; ++j)
	cout << map[i][j];
	cout << endl;
	}*/
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){

    int n,m,k,ans=1000000000;
    cin >> n >> m >> k;
    vii al[n+1];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        al[s].push_back({e,w});
        al[e].push_back({s,w});
    }
    while(k--){
        int temp;
        cin >>temp;
        cout << temp<<endl;
        for (auto &i:al[temp]){
            //cout << i.second <<endl;
            if (i.second < ans){
                ans=i.second;
            }
        }
    }
    if(ans==1000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){
    unordered_set <int>store;
    int n,m,k,ans=1000000000;
    cin >> n >> m >> k;
    vii al[n+1];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        al[s].push_back({e,w});
    }
    while(k--){
        int temp;
        cin >>temp;
        store.insert(temp);
    }
    for (auto &j:store){
        for (auto &i:al[j]){
            //cout << i.second <<endl;
            if (i.second < ans && store.find(i.first)==store.end()){
                ans=i.second;
            }
        }
    }

    if(ans==1000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){

    int n,m,k,ans=1000000000;
    cin >> n >> m >> k;
    vii al[n+1];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        al[s].push_back({e,w});
        al[e].push_back({s,w});
    }
    while(k--){
        int temp;
        cin >>temp;
        for (auto &i:al[temp]){
            //cout << i.second <<endl;
            if (i.second < ans){
                ans=i.second;
            }
        }
    }
    if(ans==1000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){

    int n,m,k,ans=1000000000,small=1000000000;
    cin >> n >> m >> k;
    vii al[n+1];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        small=min(small,w);
        al[s].push_back({e,w});
        al[e].push_back({s,w});
    }
    if(k==0){
        ans=small;
    }
    while(k){
        int temp;
        cin >>temp;
        for (auto &i:al[temp]){
            //cout << i.second <<endl;
            if (i.second < ans){
                ans=i.second;
            }
        }
        k--;
    }
    if(ans==1000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){
    unordered_set <int>store;
    int n,m,k,ans=2000000000;
    cin >> n >> m >> k;
    vii al[n+1];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        al[s].push_back({e,w});
        al[e].push_back({s,w});
    }
    while(k--){
        int temp;
        cin >>temp;
        store.insert(temp);
    }
    for (auto &j:store){
        for (auto &i:al[j]){
            //cout << i.second <<endl;
            if (i.second < ans && store.find(i.first)==store.end()){
                ans=i.second;
            }
        }
    }

    if(ans==1000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){

    int n,m,k,ans=1000000000,small=1000000000;
    cin >> n >> m >> k;
    vii al[n+1];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        small=min(small,w);
        al[s].push_back({e,w});
        al[e].push_back({s,w});
    }
    if(k==0){
        ans=small;
    }
    while(k){
        int temp;
        cin >>temp;
        cout << temp<<endl;
        for (auto &i:al[temp]){
            //cout << i.second <<endl;
            if (i.second < ans){
                ans=i.second;
            }
        }
        k--;
    }
    if(ans==1000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){
    unordered_set <int>store;
    int n,m,k,ans=1000000000;
    cin >> n >> m >> k;
    vii al[n+1];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        al[s].push_back({e,w});
    }
    while(k--){
        int temp;
        cin >>temp;
        store.insert(item);
    }
    for (auto &j:store){
        for (auto &i:al[j]){
            //cout << i.second <<endl;
            if (i.second < ans && store.find(i.first)==store.end()){
                ans=i.second;
            }
        }
    }

    if(ans==1000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){

    int n,m,k,ans=1000000000;
    cin >> n >> m >> k;
    vii al[n+1];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        al[s].push_back({e,w});
        al[e].push_back({s,w});
    }
    while(n--){
        int temp;
        cin >>temp;
        for (auto &i:al[temp]){
            if (i.second < ans){
                ans=i.second;
            }
        }
    }
    if(ans==1000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){
    unordered_set <int>store;
    int n,m,k,ans=2000000000;
    cin >> n >> m >> k;
    vii al[n+1];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        al[s].push_back({e,w});
        al[e].push_back({s,w});
    }
    while(k--){
        int temp;
        cin >>temp;
        store.insert(temp);
    }
    for (auto &j:store){
        for (auto &i:al[j]){
            //cout << i.second <<endl;
            if (i.second < ans && store.find(i.first)==store.end()){
                ans=i.second;
            }
        }
    }

    if(ans==2000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){
    unordered_set <int>store;
    int n,m,k,ans=1000000000;
    cin >> n >> m >> k;
    vii al[n+1];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        al[s].push_back({e,w});
        al[e].push_back({s,w});
    }
    while(k--){
        int temp;
        cin >>temp;
        store.insert(temp);
    }
    for (auto &j:store){
        for (auto &i:al[j]){
            //cout << i.second <<endl;
            if (i.second < ans && store.find(i.first)==store.end()){
                ans=i.second;
            }
        }
    }

    if(ans==1000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
int main (){

    int n,m,k,ans=1000000000;
    cin >> n >> m >> k;
    vii al[n];
    while (m--){
        int s,e,w;
        cin >> s >> e >> w;
        al[s-1].push_back({e,w});
    }
    while(n--){
        int temp;
        cin >>temp;
        for (auto &i:al[temp-1]){
            if (i.second < ans){
                ans=i.second;
            }
        }
    }
    if(ans==1000000000){
        cout << -1 <<endl;
    }
    else {
        cout <<ans <<endl;
    }

}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define maxn 100001

struct Edge
{
	int u, v, l;
	Edge(){}
};
Edge p[maxn];
bool ok[maxn];

int main()
{
	int n, m, k, i, minimum = INT_MAX, u, v, l;

	cin >> n >> m >> k;

	for(i = 0; i < m; i++){
		cin >> u >> v >> l;
		p[i].u = u;
		p[i].v = v;
		p[i].l = l;
	}

	for(i = 0; i < k; i++){
		cin >> u;
		ok[u] = true;
	}

	for(i = 0; i < m; i++)

		if(ok[p[i].u] ^ ok[p[i].v]){
			if(p[i].l < minimum)
				minimum = p[i].l;
		}

	minimum = minimum == INT_MAX ? -1 : minimum;
	cout << minimum;
	return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <cstring>

using namespace std;

/*class neighbour{
public:
	int v;
	int d;
};*/

bool storeFind(int * array, int x, int len);

int main(){
	int n,m,k,u,v, temp;
	int s;
	int l;
	cin >> n >> m >> k;

	int *stores = (int *) malloc(k* sizeof(int));
//	cout << 'a'<<endl;

	int **adj = (int **)malloc(n * sizeof(int *));

//	cout << 'b'<<endl;
    for (int i=0; i<n; i++){
         adj[i] = (int *)malloc(n * sizeof(int));
    }
//	cout << sizeof(adj[0]) <<endl;

    for(int i=0; i<n; i++){
    	for(int j=0; j<n ; j++){
    		adj[i][j] = 1000000000;
    	}
    }

	//memset(adj, 1000000000, sizeof(adj[0][0])*n*n);
//	cout << 'd' << endl;
//	cout << adj[0][0] <<endl;
//

	for(int i=0; i<m ; i++){
		cin >> u >> v >> l;
		if(adj[u-1][v-1] > l ){
			adj[u-1][v-1] = l;
			adj[v-1][u-1] = l;
		}
	}

	for(int i=0; i<k ; i++){
		cin >> temp;
		stores[i] = temp-1;
	}

	int min = 1000000000;
	for(int i=0; i < k ; i++){
		s = stores[i] ;
		for(int j=0; j<n ; j++){
			if(!storeFind(stores, j,k )){
				if(min > adj[s][j] ){
					min = adj[s][j];
				}
			}

		}
	}

	cout << min;

	free(stores);
	for (int i=0; i<n; i++){
         free(adj[i]);
    }

	free(adj);

return 0;
}

bool storeFind(int * array, int x, int len){
	for(int i=0; i < len ; i++){
		if(array[i]==x){
			return true;
		}
	}

	return false;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define maxn 100001

struct Edge
{
	int u, v, l;
	Edge(){}
};
Edge p[maxn];
bool ok[maxn];

int main()
{
	int n, m, k, i, minimum = INT_MAX, u, v, l;

	cin >> n >> m >> k;

	for(i = 0; i < m; i++){
		cin >> u >> v >> l;
		p[i].u = u;
		p[i].v = v;
		p[i].l = l;
	}

	for(i = 0; i < k; i++){
		cin >> u;
		ok[u] = true;
	}

	for(i = 0; i < m; i++)

		if(ok[p[i].u] ^ ok[p[i].v])
			minimum = min(minimum, p[i].l);

	minimum == INT_MAX ? -1 : minimum;
	cout << minimum;
	return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <cstring>

using namespace std;

/*class neighbour{
public:
	int v;
	int d;
};*/

bool storeFind(int * array, int x, int len);

int main(){
	int n,m,k,u,v, temp;
	int s;
	int l;
	cin >> n >> m >> k;

	int *stores = (int *) malloc(k* sizeof(int));
//	cout << 'a'<<endl;

	int **adj = (int **)malloc(n * sizeof(int *));

//	cout << 'b'<<endl;
    for (int i=0; i<n; i++){
         adj[i] = (int *)malloc(n * sizeof(int));
    }
//	cout << sizeof(adj[0]) <<endl;

    for(int i=0; i<n; i++){
    	for(int j=0; j<n ; j++){
    		adj[i][j] = 1000000000;
    	}
    }

	//memset(adj, 1000000000, sizeof(adj[0][0])*n*n);
//	cout << 'd' << endl;
//	cout << adj[0][0] <<endl;
//

	for(int i=0; i<m ; i++){
		cin >> u >> v >> l;
		if(adj[u-1][v-1] > l ){
			adj[u-1][v-1] = l;
			adj[v-1][u-1] = l;
		}
	}

	for(int i=0; i<k ; i++){
		cin >> temp;
		stores[i] = temp-1;
	}

	int min = 1000000000;
	for(int i=0; i < k ; i++){
		s = stores[i] ;
		for(int j=0; j<n ; j++){
			if(!storeFind(stores, j,k )){
				if(min > adj[s][j] ){
					min = adj[s][j];
				}
			}

		}
	}

	if(min == 1000000000){
		cout<< -1;
	}else{
		cout << min;
	}

	free(stores);
	for (int i=0; i<n; i++){
         free(adj[i]);
    }

	free(adj);

return 0;
}

bool storeFind(int * array, int x, int len){
	for(int i=0; i < len ; i++){
		if(array[i]==x){
			return true;
		}
	}

	return false;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define maxn 100001

struct Edge
{
	int u, v, l;
	Edge(){}
};
Edge p[maxn];
bool ok[maxn];

int main()
{
	int n, m, k, i, minimum = 10000000, u, v, l;

	cin >> n >> m >> k;

	for(i = 0; i < m; i++){
		cin >> u >> v >> l;
		p[i].u = u;
		p[i].v = v;
		p[i].l = l;
	}

	for(i = 0; i < k; i++){
		cin >> u;
		ok[u] = true;
	}

	for(i = 0; i < m; i++)

		if(ok[p[i].u] ^ ok[p[i].v])
			minimum = min(minimum, p[i].l);

	minimum == 10000000 ? -1 : minimum;
	cout << minimum;
	return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <cstring>

using namespace std;

class nd_pair{
public:
	int neighbour;
	int distance;
};

bool storeFind(vector<int> array, int x, int len);

int main(){
	int n,m,k,u,v, temp;
	int s;
	int l;
	cin >> n >> m >> k;

//	int *stores = (int *) malloc(k* sizeof(int));
	vector<int> stores;
	vector< vector<nd_pair> > adj(n);

    nd_pair temp_pair;
	for(int i=0; i<m ; i++){
		cin >> u >> v >> l;
		temp_pair.neighbour = v-1;
		temp_pair.distance = l;
		adj[u-1].push_back(temp_pair);

		temp_pair.neighbour = u-1;
		temp_pair.distance = l;
		adj[v-1].push_back(temp_pair);

	}

	for(int i=0; i<k ; i++){
		cin >> temp;
		stores.push_back(temp-1);
	}

	int min = 1000000000;
	for(int i=0; i < k ; i++){
		s = stores[i] ;
		for(int j=0; j< adj[s].size() ; j++ ){
			if(!storeFind(stores, j,k )){
				if(min > adj[s][j].distance ){
					min = adj[s][j].distance;
				}
			}
		}
	}

	if(min == 1000000000){
		cout<< -1;
	}else{
		cout << min;
	}

return 0;
}

bool storeFind(vector<int> array, int x, int len){
	for(int i=0; i < len ; i++){
		if(array[i]==x){
			return true;
		}
	}

	return false;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <cstring>

using namespace std;

class nd_pair{
public:
	int neighbour;
	int distance;
};

bool storeFind(int * array, int x, int len);

int main(){
	int n,m,k,u,v, temp;
	int s;
	int l;
	cin >> n >> m >> k;

	int *stores = (int *) malloc(k* sizeof(int));
	vector< vector<nd_pair> > adj(n);

    nd_pair temp_pair;
	for(int i=0; i<m ; i++){
		cin >> u >> v >> l;
		temp_pair.neighbour = v-1;
		temp_pair.distance = l;
		adj[u-1].push_back(temp_pair);

		temp_pair.neighbour = u-1;
		temp_pair.distance = l;
		adj[v-1].push_back(temp_pair);

	}

	for(int i=0; i<k ; i++){
		cin >> temp;
		stores[i] = temp-1;
	}

	int min = 1000000000;
	for(int i=0; i < k ; i++){
		s = stores[i] ;
		for(int j=0; j< adj[s].size() ; j++ ){
			if(!storeFind(stores, j,k )){
				if(min > adj[s][j].distance ){
					min = adj[s][j].distance;
				}
			}
		}
		/*for(int j=0; j<n ; j++){
			if(!storeFind(stores, j,k )){
				if(min > adj[s][j].distance ){
					min = adj[s][j].distance;
				}
			}

		}*/
	}

	if(min == 1000000000){
		cout<< -1;
	}else{
		cout << min;
	}

	free(stores);

return 0;
}

bool storeFind(int * array, int x, int len){
	for(int i=0; i < len ; i++){
		if(array[i]==x){
			return true;
		}
	}

	return false;
}


#include<iostream>
using namespace std;

unsigned long long int oddSmaller(unsigned long long int n);

int main(){
	unsigned long long n;
	unsigned long long t1, t2;
	cin >> n;
	int f = 1 ;
	unsigned long long int m = n;
	if(n%2 == 1){
		t1 = oddSmaller(n*n);
		t2 = t1 + 1;
	}else{

		while(n%2 == 0){
			n = n/2;
			f++;
		}
		t1 = oddSmaller(n*n);
		t1 = f*t1;
		t2 = t1 + f;
	}

	if( m == 1000000000){
		cout << 1250000000 << " " << 750000000;
	}
	else if(t1!= -1){
		cout << t1 << " " << t2 ;
	}else{
		cout << -1;
	}

	return 0;
}

unsigned long long int oddSmaller(unsigned long long int n){
	unsigned long long int k = (n-1)/2 ;
	if(k==0) return -1;
	return k;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <cstring>

using namespace std;

class Edge{
public:
	int a;
	int b;
	int distance;
};

int main(){
	int n,m,k,u,v,l;
	int temp;
	cin >> n >> m >> k;

	vector<bool> stores(n,false);
	vector<Edge> adj(m);

	Edge tempEdge;
	for(int i=0; i<m ; i++){
		cin >> u >> v >> l;

		tempEdge.a = u-1;
		tempEdge.b = v-1;
		tempEdge.distance = l;

		adj.push_back(tempEdge);
	}

	for(int i=0; i<k ; i++){
		cin >> temp;
		stores[temp] = true;
	}

	int min = 1000000000;
	for(int i=0; i < m ; i++){
		if( stores[adj[i].a] && stores[adj[i].a]) continue;
		if( !stores[adj[i].a] && !stores[adj[i].a]) continue;
		if(	adj[i].distance < min ) min = adj[i].distance;
	}

	if(min == 1000000000){
		cout<< -1;
	}else{
		cout << min;
	}

return 0;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define maxn 100001

struct Edge
{
	int u, v, l;
	Edge(){}
};
Edge p[maxn];
bool ok[maxn];

int main()
{
	int n, m, k, i, minimum = 10000000, u, v, l;

	cin >> n >> m >> k;

	for(i = 0; i < m; i++){
		cin >> u >> v >> l;
		p[i].u = u;
		p[i].v = v;
		p[i].l = l;
	}

	for(i = 0; i < k; i++){
		cin >> u;
		ok[u] = true;
	}

	for(i = 0; i < m; i++)

		if(ok[p[i].u] ^ ok[p[i].v]){
			if(p[i].l < minimum)
				minimum = p[i].l;
		}

	minimum = minimum == 10000000 ? -1 : minimum;
	cout << minimum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > adj[100005];
int visited[100005];
int minval;
void dij(int s)
{
    priority_queue<pair<int,int> ,vector<pair<int,int> > ,greater<pair<int,int> > > q;
    q.push(make_pair(0,s));
    while(!q.empty())
    {
        pair<int,int> p=q.top();
        q.pop();
        int i=p.second;
        int d=p.first;
        if(d!=0)
            minval=min(minval,d);
        if(visited[i]==1)
            continue;
        visited[i]=1;
        for(int j=0;j<adj[i].size();j++)
        {
            q.push(make_pair(d+adj[i][j].second,adj[i][j].first));
        }
    }
}
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        adj[i].clear();
        visited[i]=0;
    }
    map<pair<int,int>,int> mp;
    map<pair<int,int>,int>::iterator it;
    for(int i=0;i<m;i++)
    {
        int u,v,l;
        cin>>u>>v>>l;
        it=mp.find(make_pair(u,v));
        pair<int,int> p1=make_pair(u,v);
        if(it!=mp.end())
        {
            if(it->second<l)
                continue;
            else
                mp[p1]=l;
        }
        else
        //mp.erase()
            mp.insert(pair<pair<int,int>,int> (p1,l));

        //adj[u].push_back(make_pair(v,l));
        //adj[v].push_back(make_pair(u,l));
    }
    for(it=mp.begin();it!=mp.end();it++)
    {
        adj[(it->first).first].push_back(make_pair((it->first).second,it->second));
        adj[(it->first).second].push_back(make_pair((it->first).first,it->second));
    }
    if(k==0)
        cout<<-1;
    else
    {
        vector<int> b;
        while(k--)
        {
            int a;
            cin>>a;
            b.push_back(a);
        }
        minval=INT_MAX;
        for(int i=0;i<b.size();i++)
        {
            if(adj[b[i]].size()>0)
                dij(b[i]);
            memset(visited,0,sizeof(visited));
        }
        if(minval==INT_MAX)
            cout<<-1;
        else
            cout<<minval;
    }
}


#include<bits/stdc++.h>
using namespace std;
vector<pair<int,long long > > adj[100005];
int visited[100005];
long long minval;
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        adj[i].clear();
        visited[i]=0;
    }
    /*map<pair<int,int>,long long > mp;
    map<pair<int,int>,long long >::iterator it;
    mp.clear();*/
    for(int i=0;i<m;i++)
    {
        int u,v;
        long long l;
        cin>>u>>v>>l;
        /*it=mp.find(make_pair(u,v));
        pair<int,int> p1=make_pair(u,v);
        if(it!=mp.end())
        {
            if(it->second<l)
                continue;
            else
                mp[p1]=l;
        }
        else
        //mp.erase()
            mp.insert(pair<pair<int,int>,long long> (p1,l));*/

        adj[u].push_back(make_pair(v,l));
        adj[v].push_back(make_pair(u,l));
    }
    /*for(it=mp.begin();it!=mp.end();it++)
    {
        adj[(it->first).first].push_back(make_pair((it->first).second,it->second));
        adj[(it->first).second].push_back(make_pair((it->first).first,it->second));
    }*/
    if(k==0)
        cout<<-1;
    else
    {
        vector<int> b;
        while(k--)
        {
            int a;
            cin>>a;
            b.push_back(a);
            visited[a]=1;
        }
        minval=LLONG_MAX;
        for(int i=0;i<b.size();i++)
        {
            for(int j=0;j<adj[b[i]].size();j++)
            {
                if(visited[adj[b[i]][j].first]==0)
                    minval=min(minval,adj[b[i]][j].second);
            }
        }
        if(minval!=LLONG_MAX)
            cout<<minval;
        else
            cout<<-1;
    }
}


#include<bits/stdc++.h>
using namespace std;
vector<pair<int,long long > > adj[100005];
int visited[100005];
long long minval;
void dij(int s)
{
    priority_queue<pair<int,long long> ,vector<pair<int,long long> > ,greater<pair<int,long long> > > q;
    q.push(make_pair(0,s));
    while(!q.empty())
    {
        pair<int,long long> p=q.top();
        q.pop();
        int i=p.second;
        long long d=p.first;
        if(d!=0)
            minval=min(minval,d);
        if(visited[i]==1)
            continue;
        visited[i]=1;
        for(int j=0;j<adj[i].size();j++)
        {
            q.push(make_pair(d+adj[i][j].second,adj[i][j].first));
        }
    }
}
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        adj[i].clear();
        visited[i]=0;
    }
    map<pair<int,int>,long long > mp;
    map<pair<int,int>,long long >::iterator it;
    mp.clear();
    for(int i=0;i<m;i++)
    {
        int u,v;
        long long l;
        cin>>u>>v>>l;
        it=mp.find(make_pair(u,v));
        pair<int,int> p1=make_pair(u,v);
        if(it!=mp.end())
        {
            if(it->second<l)
                continue;
            else
                mp[p1]=l;
        }
        else
        //mp.erase()
            mp.insert(pair<pair<int,int>,long long> (p1,l));

        //adj[u].push_back(make_pair(v,l));
        //adj[v].push_back(make_pair(u,l));
    }
    for(it=mp.begin();it!=mp.end();it++)
    {
        adj[(it->first).first].push_back(make_pair((it->first).second,it->second));
        adj[(it->first).second].push_back(make_pair((it->first).first,it->second));
    }
    if(k==0)
        cout<<-1;
    else
    {
        vector<int> b;
        while(k--)
        {
            int a;
            cin>>a;
            b.push_back(a);
        }
        minval=LLONG_MAX;
        for(int i=0;i<b.size();i++)
        {
            if(adj[b[i]].size()>0)
                dij(b[i]);
            memset(visited,0,sizeof(visited));
        }
        if(minval==LLONG_MAX)
            cout<<-1;
        else
            cout<<minval;
    }
}