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 <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <queue>

using namespace std;

#define SZ(v) ((int)(v).size())
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
const int maxint = -1u>>1;

#define sqr(x) ((x) * (x))

const double inf = 1e20;
    
int n, m;
double g[111][111];
int pre[111], id[111], mark[111], st[111], top, lft;
double cost[111];
bool v[111];

bool find_circle() {
    fill (v, v + n, false);
    for (int i = 1; i < n; ++i) {
        if (id[i] != i || v[i]) {
            continue;
        }
        fill (mark, mark + n, -1);
        top = 0;
        int temp = i;
        while (temp != 0 && mark[temp] == -1 && !v[temp]) {
            v[temp] = true;
            mark[temp] = top;
            st[top++] = temp;
            temp = pre[temp];
            //printf ("temp here %d\n", temp);
        }
        //printf ("temp %d mark %d\n", temp, mark[temp]);
        if (mark[temp] != -1) {
            lft = mark[temp];
            return true;
        }
    }
    return false;
}

double combine() {
    double res = 0.0;
    int now = st[lft];
    for (int i = lft; i < top; ++i) {
        int temp = st[i];
        res += cost[temp];
        id[temp] = now;
        for (int j = 0; j < n; ++j) {
            if (g[j][temp] != -1) {
                double tcost = g[j][temp] - cost[temp];
                if (g[j][now] == -1 || tcost < g[j][now])
                    g[j][now] = tcost;
            }
            if ((g[temp][j] != -1 && g[temp][j] < g[now][j]) || g[now][j] == -1) {
                g[now][j] = g[temp][j];
            }
        }
    }
    cost[now] = inf;
    for (int i = 1; i < n; ++i) {
        if (id[i] == i) {
            pre[i] = id[pre[i]];
        }
    }
    for (int i = 0; i < n; ++i) {
        if (i != now && id[i] == i && g[i][now] != -1 && g[i][now] < cost[now]) {
            pre[now] = i, cost[now] = g[i][now];
        }
    }
    return res;
}

double gao() {
    id[0] = 0;
    repf (i, 1, n - 1) {
        id[i] = i;
        cost[i] = inf;
        for (int j = 0; j < n; ++j) {
            if (i != j && g[j][i] != -1 && g[j][i] < cost[i]) {
                cost[i] = g[j][i];
                pre[i] = j;
            }
        }
    }
    double ans = 0;
    while (find_circle()) ans += combine();
    repf (i, 1, n - 1) {
        if (id[i] == i) {
            ans += cost[i];
        }
    }
    return ans;
}

double a[111][111], len[111];

int main() {
    while (scanf ("%d%d", &n, &m) != EOF) {
        rep (i, m) {
            len[i] = 0;
            rep (j, n) {
                scanf ("%lf", &a[i][j]);
                len[i] += a[i][j] * a[i][j];
            }
            len[i] = sqrt(len[i]);
        }
        rep (i, m) {
            rep (j, m) {
                if (i == j) continue;
                double now = 0.0;
                rep (k, n) {
                    now += a[i][k] * a[j][k];
                }
                now /= len[i] * len[j];
                now = sqrt (1.0 - now * now);
                g[j + 1][i + 1] = sqr(len[i] * now);
            }
            g[0][i + 1] = sqr(len[i]);
            g[i + 1][0] = -1;
            g[i + 1][i + 1] = -1;
        }
        g[0][0] = -1;
        n = m + 1;
        printf ("%.8lf\n", gao());
    }
    return 0;
}