#include<bits/stdc++.h>
using namespace std;
int n,ans = 0;
string a[32][32];
int lx[4]={0,1,0,-1};
int ly[4]={1,0,-1,0};
void SB(int x,int y)
{
a[x][y] = '-1';
for(int i = 0; i < 4;i++)
{
int tx = x + lx[i];
int ty = y + ly[i];
if(tx >= 1 && tx <= n && ty >= 1 && ty <= n && a[tx][ty] == "0")
{
SB(tx,ty);
}
}
}
int main(){
cin >> n;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n;j++)
{
cin >> a[i][j];
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1;j <= n; j++)
{
if((i == 1||i == n||j == 1 || j == n) && a[i][j] == "0")
{
SB(i,j);
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1;j <= n; j++)
{
if(a[i][j] == "0")
{
ans++;
}
}
}
cout << ans;
return 0;
}
/**************************************************************
Problem: 1913
User: yangwanning
Language: C++
Result: Runtime Error
****************************************************************/