Buggy python submission (verdict: Runtime Error):
dp=[[0 for j in range(10)] for i in range(10)]

h,w=map(int,input().split())
for i in range(10):
    s=list(map(int,input().split()))
    for j in range(10):
        dp[i][j]=s[j]

for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(h):
    s=list(map(int,input().split()))
    for j in range(w):
        if s[j]==-1 or s[j]==1:
            continue
        else:
            c+=dp[s[j]][i]
print(c)


Fixed submission:
dp=[[0 for j in range(10)] for i in range(10)]

h,w=map(int,input().split())
for i in range(10):
    s=list(map(int,input().split()))
    for j in range(10):
        dp[i][j]=s[j]

for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(h):
    s=list(map(int,input().split()))
    for j in range(w):
        if s[j]!=-1 and s[j]!=1:
            c+=dp[s[j]][1]
print(c)

Buggy python submission (verdict: Runtime Error):
dp=[[0 for j in range(10)] for i in range(10)]
#print(dp)
h,w=map(int,input().split())
for i in range(10):
    s=list(map(int,input().split()))
    for j in range(10):
        dp[i][j]=s[j]

#print(dp)

for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
#print(dp)
c=0
for i in range(h):
    s=list(map(int,input().split()))
    for j in range(w):
        if s[j]==-1 or s[j]==1:
            continue
        else:
            c+=dp[s[j]][i]
            #print(s[j])
            #print(c)

#print(dp)
print(c)


Fixed submission:
dp=[[0 for j in range(10)] for i in range(10)]

h,w=map(int,input().split())
for i in range(10):
    s=list(map(int,input().split()))
    for j in range(10):
        dp[i][j]=s[j]

for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(h):
    s=list(map(int,input().split()))
    for j in range(w):
        if s[j]!=-1 and s[j]!=1:
            c+=dp[s[j]][1]
print(c)

Buggy python submission (verdict: Runtime Error):
dp=[[0 for j in range(10)] for i in range(10)]
#print(dp)
h,w=map(int,input().split())
for i in range(10):
    s=list(map(int,input().split()))
    for j in range(10):
        dp[i][j]=s[j]

#print(dp)

for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
#print(dp)
c=0
for i in range(h):
    s=list(map(int,input().split()))
    for j in range(w):
        if s[j]==-1 or s[j]==1:
            continue
        else:
            c+=dp[s[j]][i]
            #print(s[j])
            #print(c)

#print(dp)
print(c)


Fixed submission:
dp=[[0 for j in range(10)] for i in range(10)]

h,w=map(int,input().split())
for i in range(10):
    s=list(map(int,input().split()))
    for j in range(10):
        dp[i][j]=s[j]

for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(h):
    s=list(map(int,input().split()))
    for j in range(w):
        if s[j]!=-1 and s[j]!=1:
            c+=dp[s[j]][1]
print(c)