import { readFileSync } from 'fs'; function Main(input: string) { const data = input.split('\n'); const numbers = data[0].split(' ').map(Number); const res = numbers.find((value, index) => value !== index + 1); if (res == null) { throw new Error('Not Found'); } console.log(res - 1); } Main(readFileSync('/dev/stdin', 'utf8'));