#include<bits/stdc++.h>
using namespace std;
const int N=110;
typedef long double db;
int n,m;
db a[N][N];
void pivot(int x,int y){
//printf("pivot %d %d\n",x,y);
db t=-a[x][y];a[x][y]=-1;
for (int i=0;i<=n;i++) a[x][i]/=t;
for (int i=0;i<=m;i++)
if (i!=x){
db t=a[i][y];a[i][y]=0;
for (int j=0;j<=n;j++) a[i][j]+=a[x][j]*t;
}
}
db simplex(){
while (1){
int x=0,y=0;
for (int i=1;i<=n;i++)
if (a[0][i]>0){y=i;break;}
if (!y) return a[0][0];
db lim=1e9;
for (int i=1;i<=m;i++)
if (a[i][y]<0&&-a[i][0]/a[i][y]<lim)
lim=-a[i][0]/a[i][y],x=i;
pivot(x,y);
}
}
int main()
{
freopen("happiness.in","r",stdin);
freopen("happiness.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++) scanf("%Lf",&a[0][i]);
for (int i=1;i<=m;i++){
for (int j=1;j<=n;j++){
scanf("%Lf",&a[i][j]);
a[i][j]=-a[i][j];
}
scanf("%Lf",&a[i][0]);
}
printf("Nasa can spend %lld taka. ",(long long)ceil(m*simplex()));
return 0;
}