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 <stdio.h>
#include <string.h>
#include <iostream>
#include <cmath>
#define clr(a,b) memset(a,b,sizeof(a))
using namespace std;

const int N=105;
const double dinf=1e10;

int n,m,pre[N],vis[N],cnt,ced[N],i,j,k;
double g[105][105],len[105];
double gra[105][105];

void dfs(int s)//dfs蛻、譏ッ蜷ヲ譛芽ァ」
{
    vis[s]=1;cnt++;
    for(int i=1;i<=n;i++)
        if(gra[s][i]<dinf&&!vis[i])
            dfs(i);
}

double ZHULIU(int s)
{
	clr(vis,0);cnt=0;
	dfs(s);if(cnt!=n)return -1;
    clr(ced,0);double ans=0;
    int i,j,k;//霑咎?逧?豈碑セ?・?束?檎ョ。莉門造
    do
	{
	    for(i=1;i<=n;i++)//貂?勁閾ェ邇ッ?御サ・蜿頑アよッ丈クェ轤ケ逧??霎ケ
	    {
	        if(ced[i]||i==s)continue;
	        pre[i]=1;
	        for(j=1;j<=n;j++)
                if(j!=s&&j!=i&&!ced[j]&&gra[pre[i]][i]>gra[j][i])
                    pre[i]=j;
	    }
	    pre[s]=s;
        for(i=1;i<=n;i++)
        {
            if(ced[i]||i==s)continue;
            clr(vis,0);
            for(j=i;j!=s&&!vis[j];j=pre[j])vis[j]=1;//蟇サ謇セ邇ッ?瑚「ォvis譬?ョー逧?弍邇ッ蜀?噪轤ケ
            if(j==s)continue;
            ans+=gra[pre[j]][j];
            for(i=pre[j];i!=j;i=pre[i])//謚顔識驥檎噪譚??蜉?芦ans荳ュ蜴サ
                ans+=gra[pre[i]][i],ced[i]=1;
            for(k=1;k<=n;k++)//霑吩クェ蜥御ク矩擇驍」荳ェfor蝨ィ郛ゥ轤ケ
                if(!ced[k]&&gra[k][j]<dinf)
                    gra[k][j]-=gra[pre[j]][j];
            for(i=pre[j];i!=j;i=pre[i])
                for(k=1;k<=n;k++)
                {
                    if(ced[k])continue;
                    gra[j][k]=min(gra[j][k],gra[i][k]);
                    if(gra[k][i]<dinf)
                        gra[k][j]=min(gra[k][j],gra[k][i]-gra[pre[i]][i]);
                }
            break;
        }
	}while(i<=n);
	for(int i=1;i<=n;i++)//謚贋ク肴弍蜑ゥ荳狗噪蜈・霎ケ驛ス蜉?ク?
        if(!ced[i]&&i!=s)ans+=gra[pre[i]][i];
	return ans;
}


int main(){
//    freopen("in.txt","r",stdin);
//    freopen("/home/axorb/in","r",stdin);
    scanf("%d%d",&m,&n);n++;
    for(i=2;i<=n;i++){
        for(j=1;j<=m;j++){
            scanf("%lf",&g[i][j]);
            len[i]+=g[i][j]*g[i][j];
        }
        len[i]=sqrt(len[i]);
        gra[1][i]=len[i]*len[i];
        gra[i][1]=dinf;
    }
    for(i=2;i<=n;i++){
        for(j=2;j<=n;j++){
            double tmp=0;
            if(i==j) gra[i][j]=dinf;
            for(k=1;k<=m;k++){
                tmp+=g[i][k]*g[j][k];
            }
            double ang=tmp/len[i]/len[j];
            ang=sqrt(1-ang*ang);
            gra[i][j]=(len[j]*ang)*(len[j]*ang);
        }
    }
    printf("%.10lf\n",ZHULIU(1));
    return 0;
}