program derangement
  implicit none
  integer :: n, a(100000), i, b(100000), m
  a = 0
  b = 0
  read(*,*) n
  read(*,*) a(1:n)
  do i = 1, n
    b(i) = 1
    if (a(i).eq.i) then
      b(i) = -1
    end if
  end do
  m = 0
  do i = 1, n-1
    if (b(i).lt.0) then
      b(i) = 1
      b(i+1) = 1
      m = m + 1
    end if
  end do
  write(*,'(i0)') m
  stop
end program derangement