process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// var table = {}; function resettable(n) { for(var i=1;i<=n;i++) table[i] = {}; table[1][1] = 0; } function outputtable(n) { for(var y=1;y<=n;y++) { var row = [] for(var x=1;x<=n;x++) row.push(table[y][x]); console.log(row.join(" ")); } } function checkpos(n, move, xpos, ypos) { if ((xpos > 0) && (xpos <= n) && (ypos > 0) && (ypos <= n) && (!(xpos in table[ypos]))) { table[ypos][xpos] = move; return true; } return false; } function performmoves(n, move, xpos, ypos, xjump, yjump) { var changed = false; changed = checkpos(n, move, xpos+xjump, ypos+yjump) || changed; changed = checkpos(n, move, xpos+xjump, ypos-yjump) || changed; changed = checkpos(n, move, xpos-xjump, ypos+yjump) || changed; changed = checkpos(n, move, xpos-xjump, ypos-yjump) || changed; if (xjump != yjump) { changed = checkpos(n, move, xpos+yjump, ypos+xjump) || changed; changed = checkpos(n, move, xpos+yjump, ypos-xjump) || changed; changed = checkpos(n, move, xpos-yjump, ypos+xjump) || changed; changed = checkpos(n, move, xpos-yjump, ypos-xjump) || changed; } return changed; } function calcmoves(n, xjump, yjump) { resettable(n); var changed = true; var move = 0; while (changed) { changed = false; for(var y=1;y<=n;y++) for (var x=1;x<=n;x++) if ((x in table[y]) && (table[y][x] == move)) { changed = performmoves(n, move+1, x, y, xjump, yjump) || changed; } move++; if (n in table[n]) return table[n][n]; } return -1; } function main() { var n = parseInt(readLine()); // your code goes here for(var yjump=1;yjump