#include <bits/stdc++.h>
using namespace std;
int main(){
int n, num[10007], lei[10007] = {0}, sum = 2;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> num[i];
}
if(n == 1 && num[1] == 1){
cout << 1 << endl;
return 0;
}
lei[1] = 1;
for(int i = 2; i <= n + 1; i++){
lei[i] = num[i - 1] - lei[i - 1] - lei[i - 2];
if(lei[i] != 1 && lei[i] != 0){
sum--;
break;
}
}
if(lei[n + 1] != 0){
sum--;
}
lei[1] = 0;
for(int i = 2; i <= n + 1; i++){
lei[i] = num[i - 1] - lei[i - 1] - lei[i - 2];
if(lei[i] != 1 && lei[i] != 0){
sum--;
break;
}
}
if(num[n + 1] != 0){
sum--;
}
cout << sum << endl;
return 0;
}