function main(input) {
  var arr1 = input.split('\n')
  var n = arr1[0]
  var arr2 = arr1[1].split(' ').map(n => +n)
  
  var min = Infinity
  for(var i = 1; i <= arr2.length; i++){
    if(arr2[i-1] === i) return console.log(0)
    if(arr2[i-1] >= i){
      min = Math.min(min, arr2[i] - i)
    }
  }
  if(min === Infinity) console.log(-1)
  console.log(min)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));