module.exports=function(r){var t={};function n(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=r,n.c=t,n.d=function(r,t,e){n.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:e})},n.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},n.t=function(r,t){if(1&t&&(r=n(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var e=Object.create(null);if(n.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)n.d(e,o,function(t){return r[t]}.bind(null,o));return e},n.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return n.d(t,"a",t),t},n.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},n.p="",n(n.s=0)}([function(r,t,n){n(1)(n(3).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,t,n){function e(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var n=[],e=!0,o=!1,u=void 0;try{for(var i,f=r[Symbol.iterator]();!(e=(i=f.next()).done)&&(n.push(i.value),!t||n.length!==t);e=!0);}catch(r){o=!0,u=r}finally{try{e||null==f.return||f.return()}finally{if(o)throw u}}return n}(r,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var o=n(2);r.exports=function(r){for(var t=e(r[0].split(" ").map(function(r){return Number(r)}),2),n=t[0],u=t[1],i=[],f=0;f<10;f++){var a=r[f+1].split(" ").map(function(r){return Number(r)});i.push(a)}for(var l=o(i),c=0,p=0;p<n;p++)for(var s=r[p+11].split(" ").map(function(r){return Number(r)}),d=0;d<u;d++)-1!=s[d]&&(c+=l[s[d]][1]);console.log(c)}},function(r,t){r.exports=function(r){arguments.length>1&&void 0!==arguments[1]&&arguments[1];for(var t=r.length,n=new Array(t),e=0;e<t;e++)n[e]=r[e].concat();for(var o=0;o<t;o++)for(var u=0;u<t;u++)for(var i=0;i<t;i++)n[o][u]>n[o][i]+n[i][u]&&(n[o][u]=n[o][i]+n[i][u]);return n}},function(r,t){r.exports=require("fs")}]);