import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); List<Integer> v = new ArrayList<>(); for(int i = 0; i < a; ++i) v.add(sc.nextInt()); if(v.size() <= 1){ //长度小于等于1直接返回 System.out.println(v.size()); return; } if(v.indexOf(0) == -1 || v.indexOf(1) == -1){ //只含0或1直接返回 System.out.println(1); return; } int pre = v.get(0), r = 1; //用pre记录前一个数字 for(int i = 1; i < v.size(); ++i){ if(v.get(i) + pre == 1){ //当前数字与pre不同,长度加一 r++; pre = 1 - pre; //更新pre } } System.out.println(r); } }