#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define INF 10000 const int maxn = 300; int r[maxn][maxn]; int main() { int n, m; while (cin>>n>>m) { memset (r, INF, sizeof(r)); int x, y, v; for (int i = 0; i < m; i++) { cin>>x>>y>>v; if (r[x][uy] > v) r[x][y] = r[y][x] = v; } for (int i = 0; i < n ;i++) r[i][i] = 0; for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (r[i][k] + r[k][j] < r[i][j]) r[i][j] = r[j][i] = r[i][k] + r[k][j]; } cin>>x>>y; if (r[x][y] < INF) cout<<r[x][y]<<endl; else cout<<"-1"<<endl; } return 0; }