import java.util.Scanner;
public class Main {
  public static void main (String [] args) {
  Scanner sc = new Scanner (System.in);
    int s = sc.nextInt();
    int a [] = new int [s/2];
    for(int i = 0; i < s/2; i++) {
      a[i] = sc.nextInt();
    }
    int c = 0;
    for(int i = 1; i < s/2; i++) {
      if(( a[i-1] != a[i]+1 && a[i-1] != a[i]-1 )&& a[i-1] % 2 != a[i] % 2) {
        if(a[i-1] != a[i]+1) a[i]++; 
        else a[i]--;
        c++;
      }
     else{
        while (a[i-1]+2 != a[i]){
               c++;
               if(a[i-1]+2 >a[i]) a[i]++;
               else if (a[i-1] < a[i]) a[i]--;
        }
    }
    }
  System.out.println(c);
}
}