#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_N (1<<19)
#define INF 100000000
#define MOD 1000000007
#define RANK 1000000000
#define EPS 1e-10
using namespace std;
typedef long long ll;
typedef pair<long double,int> P;

int n, m;
long double v[100][100];
int saw[101];
int com[101];
bool dead[101];
vector<P> e[101];
vector<P> rev[101];
vector<P> ee[101];
P ree[101];

int dfs_liu(int v, int o){
    saw[v] = o;
    rep(i,ee[v].size()){
        P p = ee[v][i];
        if(saw[p.second] >= 0 && saw[p.second] < o) continue;
        if(saw[p.second] == o){
            com[p.second] = p.second;
            while(v != p.second){
                com[v] = p.second;
                v = ree[v].second;
            }
            return p.second;
        }
        int rec = dfs_liu(p.second,o);
        if(rec != -1) return rec;
    }
    return -1;
}

long double chu_liu(){
    long double ret = 0.0;
    memset(dead,0,sizeof(dead));
    int debug = 0;
    while(true){
        debug++;
        bool end = true;
        rep(i,n){
            ee[i].clear();
            rev[i].clear();
        }
        rep(i,n) rep(j,e[i].size()){
            if(dead[i] == true || dead[e[i][j].second] == true) continue;
            rev[e[i][j].second].push_back(P(e[i][j].first,i));
        }
        /*
        rep(i,n){
            if(dead[i])  continue;
            sort(rev[i].begin(),rev[i].end());
        }
        */
        //cout << "Ho" << endl;
        memset(saw,-1,sizeof(saw));
        memset(com,-1,sizeof(com));
        rep(i,n){
            if(dead[i]) continue;
            if(rev[i].size() == 0) continue;
            long double mi = 100.0;
            rep(j,rev[i].size()) mi = min(mi,rev[i][j].first+EPS);
            rep(j,rev[i].size()){
                if(rev[i][j].first < mi){
                    ee[rev[i][j].second].push_back(P(rev[i][j].first,i));
                    ree[i] = rev[i][j];
                    break;
                }
            }
        }
        rep(i,n){
            rep(j,ee[i].size()){
                //cout << i << " " << ee[i][j].second << " " << ee[i][j].first << endl;
            }
        }
        //cout << "o" << endl;
        int d;
        rep(i,n){
            if(dead[i]) continue;
            if(saw[i] >= 0) continue;
            d = dfs_liu(i,i);
            if(d >= 0){
                end = false;
                break;
            }
        }
        //rep(i,n) cout << saw[i] << " ";
        //cout << endl;
        //rep(i,n) cout << com[i] << " ";
        //cout << endl;
        //cout << d << endl;
        if(end) break;
        rep(i,n){
            if(dead[i]) continue;
            rep(j,e[i].size()){
                if(com[i] == d && com[e[i][j].second] == d){
                    e[i][j].first = 100.0;
                    continue;
                }
                if(com[e[i][j].second] == d){
                    e[i][j].first -= ree[e[i][j].second].first;
                    e[i][j].second = d;
                    continue;
                }
                if(com[i] == d){
                    if(i != d) e[d].push_back(e[i][j]);
                }
            }
        }
        rep(i,n){
            if(dead[i]) continue;
            if(com[i] == d){
                ret += ree[i].first;
                if(i != d) dead[i] = true;
            }
        }
    }
    rep(i,n){
        if(dead[i]) continue;
        ret += ree[i].first;
    }
    return ret;
}

int main(){
    cin >> m >> n;
    rep(i,n) rep(j,m) cin >> v[i][j];
    rep(i,n){
        long double d = 0.0;
        rep(j,m) d += v[i][j]*v[i][j];
        if(d == 0.0) continue;
        e[n].push_back(P(d,i));
        rev[i].push_back(P(d,n));
        rep(j,n){
            if(i == j) continue;
            long double ss = -10000000000.0, ee = 100000000000.0, ms, me;
            long double vs, ve;
            rep(u,200){
                ms = (ss*2+ee)/3;
                me = (ss+ee*2)/3;
                vs = 0.0; ve = 0.0;
                rep(k,m){
                    vs += pow(v[j][k]+ms*v[i][k],2);
                    ve += pow(v[j][k]+me*v[i][k],2);
                }
                if(vs > ve) ss = ms;
                else ee = me;
            }
            e[i].push_back(P(vs,j));
            rev[i].push_back(P(vs,i));
        }
    }
    n++;
    rep(i,n){
        rep(j,e[i].size()){
            //cout << i << " " << e[i][j].second << " " << e[i][j].first << endl;
        }
    }
    long double ans = chu_liu();
    printf("%.9Lf\n",ans);
}

Measured memory_bytes: 4904