module.exports=function(e){var r={};function n(t){if(r[t])return r[t].exports;var o=r[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)n.d(t,o,function(r){return e[r]}.bind(null,o));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=0)}([function(e,r,n){n(1)(n(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n"),n=Number(r[0]),t=[],o=0;o<n;o++){var u=r[o+1].split(" ").map(function(e){return Number(e)-1});t.push(u)}for(var i=n*(n-1)/2,f=new Array(n).fill(0),l=0;l<=i;l++){for(var c=!0,a=new Array(n).fill(0),p=!0,s=0;s<n;s++)if(1!=a[s])if(f[s]>=n-1)a[s]=1,p=!1;else{c=!1;var d=t[s][f[s]];0==a[d]&&t[d][f[d]]==s&&(a[s]=1,a[d]=1,p=!1)}for(var v=0;v<n;v++)1==a[v]&&(f[v]+=1);if(c)return void console.log(l);if(p)return void console.log(-1)}console.log(-1)}},function(e,r){e.exports=require("fs")}]);