#include<bits/stdc++.h>
#define sz 105
#define ll long long
#define INF INT_MAX
using namespace std;
//WA on test 12
ll n, m, beauty;
ll dp[sz][sz][sz];
ll col[sz];
ll cost[sz][sz];
int main(){
cin>>n>>m>>beauty;
for(ll i=0; i<sz; i++){
for(ll j=0; j<sz; j++) memset(dp[i][j], -1, sizeof(dp[i][j]));
}
for(ll i=1; i<=n; i++) cin>>col[i];
for(ll i=1; i<=n; i++){
for(ll j=1; j<=m; j++){
cin>>cost[i][j];
}
}
if(col[1]!=0){
dp[1][1][col[1]]=0;
}
else{
for(ll i=1; i<=m; i++){
dp[1][1][i] = cost[1][i];
}
}
ll mn, m1, m2;
for(ll i=2; i<=n; i++){
for(ll j=1; j<=beauty; j++){
mn = INF;
if(col[i]!=0){
for(ll k=1; k<=m; k++){
if(k==col[i]) continue;
if(dp[i-1][j-1][k]!=-1){
mn = min(mn, dp[i-1][j-1][k]);
}
}
if(mn!=INF) dp[i][j][col[i]] = mn;
if(dp[i-1][j][col[i]]!=-1){
dp[i][j][col[i]] = min(dp[i-1][j][col[i]], mn);
}
}
else{
m1=m2=INF;
for(ll l=1; l<=m; l++){
ll v = dp[i-1][j-1][l];
if(v!=-1){
if(m1>v){
m2=m1;
m1=v;
}
else if(m1==v) m2=v;
else if(m2>v) m2=v;
}
}
for(ll k=1; k<=m; k++){
if(m1!=INF){
if(dp[i-1][j-1][k]==m1){
mn = m2+cost[i][k];
}else mn = m1+cost[i][k];
}
if(mn!=INF) dp[i][j][k] = mn;
if(dp[i-1][j][k]!=-1){
dp[i][j][k] = min(dp[i-1][j][k]+cost[i][k], mn);
}
}
}
}
}
// for(ll i=1; i<=n; i++){
// cout<<"\nFor i="<<i<<endl;
// for(ll j=1; j<=beauty; j++){
// cout<<j<<": ";
// for(ll k=1; k<=m; k++){
// cout<<dp[i][j][k]<<" ";
// }cout<<"\n";
// }
// }
mn=INF;
if(col[n]!=0) cout<<dp[n][beauty][col[n]];
else{
for(ll i=1; i<=m; i++){
mn = min(dp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