include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
const int N=510,M=1E5+10,inf=0x3f3f3f3f;
int dist[N],book[N],e[N][N];
int n,m;
void init()
{ for(int i=1;i<=n;i)
for(int j=1;j<=n;j)
{
if(i==j)
e[i][j]=0;
else e[i][j]=inf;
}
for(int i=1;i<=m;i)
{
int a,b,c;
cin>>a>>b>>c;
e[b][a]=e[a][b]=min(c,e[a][b]);
}
}
int main()
{
cin>>n>>m;
init();
for(int i=1;i<=n;i)
{
dist[i]=e[1][i];
}
book[1]=1;
int sum=0;
int flag=1;
for(int i=1;i<=n-1&[HTML_REMOVED]i)
{
int minx=inf;
int u;
for(int j=1;j<=n;j)
{
if(book[j]==0&&minx>dist[j])
minx=dist[u=j];
}
if(minx==inf)
{
flag=0;break;
}
book[u]=1;sum+=dist[u];
for(int v=1;v<=n;v++)
{
if(book[v]==0&&dist[v]>e[u][v])
dist[v]=e[u][v];
}
}
if(flag)
cout <<sum;
else cout <<"impossible";
}