#include #include using namespace std; const int N=3005; #define inf 0x3f3f3f3f int fa[N]; int sum[N]; int n,m; int find(int x) { if(fa[x]==x) return x; return fa[x]=find(fa[x]); } bool merge(int x,int y) { int fx=find(x); int fy=find(y); if(fx!=fy) { fa[fx]=fy; return true; } return false; } int main() { while(~scanf("%d%d",&n,&m)) { int ans=n-1; memset(sum,0,sizeof(sum)); for(int i=0;isum[i]) min=sum[i]; cout<