import * as fs from 'fs'; function main(input: Array) { const n = Number(input[0]); const block_length_list = input[1].split(' ').map(x => Number(x)); let head = block_length_list[0]; const min_length = 1; let counter = 0; while(head != min_length) { swap(0, block_length_list.indexOf(head - 1), block_length_list); head = block_length_list[0]; counter++; } console.log(counter); } function swap(origin, target, list) { const tmp = list[origin]; list[origin] = list[target]; list[target] = tmp; } main(fs.readFileSync('/dev/stdin', 'utf8').split('\n'));