就是找连续1和连续0的个数之和
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static int N = (int) (1e6 + 10);
static int n;
static int[] a = new int[N];
static int cnt = 0;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception {
n = Integer.parseInt(br.readLine());
String[] strs = br.readLine().split(" ");
for(int i = 1 ; i<= n ; i ++) {
a[i] = Integer.parseInt(strs[i - 1]);
}
// 统计有多少个连续的 0 和 1
for(int i = 1; i <= n ; i ++) {
if(a[i] == 0) {
cnt ++;
while(i <= n && a[i] == 0) {
i ++;
}
i --;
}
if(a[i] == 1) {
cnt ++;
while(i <= n &&a[i] == 1) {
i ++;
}
i --;
}
}
System.out.println(cnt);
}
}