#include<bits/stdc++.h>
using namespace std;
long long A,B,ans,tot=0,lead[10010];
struct edge{
long long from,to,w;
}e[10010];
bool cmp(edge x,edge y)
{
if(x.w<y.w)
return true;
return false;
}
void init()
{
cin>>A>>B;
for(long long i=1;i<=B;i++)
for(long long j=1;j<=B;j++)
{
long long x;
cin>>x;
if(x!=0&&i>j)
{
e[++tot].from=i;
e[tot].to=j;
e[tot].w=x;
}
}
for(long long i=1;i<=B;i++)
{
e[++tot].from=0;
e[tot].to=i;
e[tot].w=A;
}
for(long long i=0;i<=B;i++)
lead[i]=i;
}
void kruskal()
{
sort(e+1,e+1+tot,cmp);
for(long long i=1;i<=tot;i++)
if(lead[e[i].from]!=lead[e[i].to])
{
ans+=e[i].w;
long long tmp=lead[e[i].from];
e[i].from=e[i].to;
for(long long j=0;j<=B;j++)
if(lead[j]==tmp)
lead[j]=lead[e[i].to];
}
}
int main()
{
init();
kruskal();
cout<<ans;
return 0;
}