#include<bits/stdc++.h>
using namespace std;
int n,m,l,f[1005][1005];
int main(){
freopen("Wrong_world.in","r",stdin);
freopen("Wrong_world.out","w",stdout);
memset(f,0x3f3f3f3f,sizeof(f));
cin>>n>>m;
for (int i=1;i<=m;i++){
cin>>l;
for (int j=1;j<=l;j++){
int x,y,z;
if (j!=1){
x=z;
}else{
cin>>x;
}
cin>>y>>z;
f[x][z]=y;
}
}
for (int k=1;k<=n;k++){
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
if (f[i][k]+f[k][j]<f[i][j]){
f[i][j]=f[i][k]+f[k][j];
}
}
}
}
cout<<f[1][n]<<" "<<f[1][n]*f[1][n];
return 0;
}