'use strict'
const Main = (arg) => {
  let input = arg.trim().split('\n');
  let N = parseInt(input[0]);
  let Arr = input[1].split(' ').map(Number);
  let count = 0;


  if (Arr.indexOf(1) === -1) {
    count = -1;
  } else {
    for (let i = 1; i <= N; i++) {
      let p = Arr.indexOf(i);

      if (p === -1) {
        break;
      } else {
        Arr.splice(0, p + 1);
        count += (p);
      }
    }
  }

  console.log(count);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
