Problem: You are recording a result of a secret experiment, which consists of a large set of N-dimensional vectors. Since the result may become very large, you are thinking of compressing it. Fortunately you already have a good compression method for vectors with small absolute values, all you have to do is to preprocess the vectors and make them small.

You can record the set of vectors in any order you like. Let's assume you process them in the order v_1, v_2,..., v_M. Each vector v_i is recorded either as is, or as a difference vector. When it is recorded as a difference, you can arbitrarily pick up an already chosen vector v_j (j<i) and a real value r. Then the actual vector value recorded is (v_i - r v_j). The values of r and j do not affect the compression ratio so much, so you don't have to care about them.

Given a set of vectors, your task is to write a program that calculates the minimum sum of the squared length of the recorded vectors.



Input

The input is like the following style.

N M
v_{1,1} v_{1,2} ... v_{1,N}
...
v_{M,1} v_{M,2} ... v_{M,N}


The first line contains two integers N and M (1 \leq N, M \leq 100), where N is the dimension of each vector, and M is the number of the vectors. Each of the following M lines contains N floating point values v_{i,j} (-1.0 \leq v_{i,j} \leq 1.0) which represents the j-th element value of the i-th vector.

Output

Output the minimum sum of the squared length of the recorded vectors. The output should not contain an absolute error greater than 10^{-6}.

Examples

Input

2 3
1.0 1.0
-1.0 0.0
0.5 0.5


Output

1.0


Input

1 1
1.0


Output

1.0


Input

4 3
1.0 1.0 0.0 0.0
-1.0 0.0 -1.0 0.0
0.5 0.5 0.5 0.5


Output

3.0

Solution (in CPP):

Solution:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
const int maxn=110;
const int maxe=50010;
struct Edge
{
	int u,v;
	double w;
}edge[maxe];
int nv,ne;
void add(int u,int v,double w)
{
	edge[ne].u=u;
	edge[ne].v=v;
	edge[ne++].w=w;
}
const double inf=1e12;
double In[maxn];
int pre[maxn],ID[maxn],vis[maxn];
double Directed_MST(int root)
{
	double ret=0;
	int i,u,v,cnt;
	while(1)
	{
		for(i=0;i<=nv;++i)In[i]=inf;
		for(i=0;i<ne;++i)
		{
			u=edge[i].u;
			v=edge[i].v;
			if(edge[i].w<In[v]&&u!=v)
			{
				In[v]=edge[i].w;
				pre[v]=u;
			}
		}
		//cout <<"root:"<<root<<" ";for(i=0;i<=nv;++i)cout <<In[i]<<" ";cout <<endl;
		for(i=0;i<=nv;++i)
			if(i!=root&&In[i]==inf)return -1;
		cnt=0;
		memset(ID,-1,sizeof(ID));
		memset(vis,-1,sizeof(vis));
		In[root]=0;
		for(i=0;i<=nv;++i)
		{
			ret+=In[i];
			for(v=i;vis[v]!=i&&ID[v]==-1&&v!=root;v=pre[v])
				vis[v]=i;
			if(v!=root&&ID[v]==-1)
			{
				for(u=pre[v];u!=v;u=pre[u])
					ID[u]=cnt;
				ID[v]=cnt++;
			}
		}
		if(cnt==0)break;
		for(i=0;i<=nv;++i)
			if(ID[i]==-1)ID[i]=cnt++;
		for(i=0;i<ne;++i)
		{
			v=edge[i].v;
			edge[i].u=ID[edge[i].u];
			edge[i].v=ID[edge[i].v];
			if(edge[i].u!=edge[i].v)
				edge[i].w-=In[v];
		}
		nv=cnt-1;
		root=ID[root];
	}
	return ret;
}
int n,m;
#define sqr(v) ((v)*(v))
struct Point
{
	double v[101];
	double length()
	{
		double res=0;
		for(int i=0;i<m;++i)
			res+=sqr(v[i]);
		return res;
	}
	Point operator -(const Point &p)
	{
		Point res;
		for(int i=0;i<m;++i)
			res.v[i]=v[i]-p.v[i];
		return res;
	}
}pt[101];
double len(int a,int b)
{
	double lena=sqrt(pt[a].length()),lenb=sqrt(pt[b].length()),res=0;
	for(int i=0;i<m;++i)
		res+=pt[a].v[i]*pt[b].v[i];
	double cosv=res/lena/lenb;
	return sqr(lenb*sin(acos(cosv)));
}
int main()
{
	int i,j;
	scanf("%d%d",&m,&n);
	for(i=1;i<=n;++i)
	{
		for(j=0;j<m;++j)
		{
			scanf("%lf",&pt[i].v[j]);
		}
		add(0,i,pt[i].length());
	}
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
		{
			if(i==j)continue;
			add(i,j,len(i,j));
		}
	nv=n;
	printf("%.9f\n",Directed_MST(0));
	return 0;
}