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 <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef pair<double,int> P;
int N,M,from[101],nid[101];
double inf=1e5,d[101][101],d2[101][101];
bool vis[101];
vector<int> cycle;
bool visit(int v,int s,int r){
	if(v==r) return 0;
	if(vis[v]) return v==s;
	cycle.pb(v);
	vis[v]=1;
	return visit(from[v],s,r);
}
double dir_msp(int r){	//root = r
	int S=N;
	bool update=1;
	while(update){
//		printf("   S=%d\n",S);
		update=0;
		double sco=0;
/*		rep(i,S){
			rep(j,S) printf("%.2f ",d[i][j]);
			puts("");
		}*/
		rep(i,S){
			if(i==r) continue;
			P mn=P(inf,-1);
			rep(j,S) if(i!=j) mn=min(mn,P(d[j][i],j));
			if(mn.fs==inf) return inf;
			from[i]=mn.sc;
			sco+=mn.fs;
//			printf("from[%d]=%d\n",i,from[i]);
//			show(sco);
		}
		rep(i,S){
			if(i==r) continue;
			rep(j,S) vis[j]=0;
			cycle.clear();
			if(!visit(i,i,r)) continue;
			update=1;
			int len=cycle.size();
			cycle.pb(cycle[0]);
			int S2=S-len+1,it=0;
			rep(j,S){
				if(!vis[j]) nid[j]=it++;
				else nid[j]=-1;
			}
			r=nid[r];
			rep(j,S) if(nid[j]!=-1){		//o->o
				rep(k,S) if(nid[k]!=-1){
					d2[nid[j]][nid[k]]=d[j][k];
				}
			}
			rep(j,S) if(nid[j]!=-1){		//i->o
				double mn=inf;
				rep(k,S) if(nid[k]==-1) mn=min(mn,d[k][j]);
				d2[S2-1][nid[j]]=mn;
			}
			double csum=0;
			rep(j,len) csum+=d[cycle[j+1]][cycle[j]];
			rep(j,S) if(nid[j]!=-1){
				double mn=inf;
				rep(k,len){
					mn=min(mn,d[j][cycle[k]]+csum-d[cycle[k+1]][cycle[k]]);
				}
				d2[nid[j]][S2-1]=mn;
			}
			S=S2;
			rep(j,S) rep(k,S) d[j][k]=d2[j][k];
			break;
		}
		if(!update) return sco;
	}
}
double v[101][100];
int main(){
	cin>>M>>N;
	rep(i,N) rep(j,M) cin>>v[i+1][j];
	N++;
	rep(i,N) rep(j,N) if(i!=j){
		double a=0,b=0,c=0,r=0;
		rep(k,M) a+=v[j][k]*v[j][k];
		rep(k,M) b+=2*v[i][k]*v[j][k];
		rep(k,M) c+=v[i][k]*v[i][k];
		if(a==0) r=0;
		else r=b/2/a;
		d[j][i]=a*r*r-b*r+c;
	}
/*	rep(i,N){
		rep(j,N) printf("%.2f ",d[i][j]);
		cout<<endl;
	}*/
	printf("%.12f\n",dir_msp(0));
}