var
c,d,n,m:longint;
a:array[0..701]of ansistring;
ans:int64;
procedure sousuo(x,y:longint);
var
i,j:longint;
begin
if y<>m then
begin
if x<>n then
if (a[x+1][y+1]='1') then
begin
a[x+1][y+1]:='0';
sousuo(x+1,y+1);
end;
if (a[x][y+1]='1') then
begin
a[x][y+1]:='0';
sousuo(x,y+1);
end;
if x<>1 then
if (a[x-1][y+1]='1') then
begin
a[x-1,y+1]:='0';
sousuo(x-1,y+1);
end;
end;
if x<>n then
if (a[x+1][y]='1') then
begin
a[x+1][y]:='0';
sousuo(x+1,y);
end;
if x<>1 then
if (a[x-1][y]='1') then
begin
a[x-1][y]:='0';
sousuo(x-1,y);
end;
if y<>1 then
begin
if x<>n then
if (a[x+1][y-1]='1') then
begin
a[x+1][y-1]:='0';
sousuo(x+1,y-1);
end;
if (a[x][y-1]='1') then
begin
a[x][y-1]:='0';
sousuo(x,y-1);
end;
if x<>1 then
if (a[x-1][y-1]='1') then
begin
a[x-1][y-1]:='0';
sousuo(x-1,y-1);
end;
end;
end;
begin
assign(input,'common.in');
assign(output,'common.out');
reset(input);
rewrite(output);
readln(n);
readln(a[1]);
m:=length(a[1]);
a[1]:=a[1]+'0';
for c:=2 to n do
begin
readln(a[c]);
a[c]:=a[c]+'0';
end;
ans:=0;
for c:=1 to n do
for d:=1 to m do
if (a[c][d]='1') then
begin
inc(ans);
a[c][d]:='0';
sousuo(c,d);
end;
writeln(ans);
close(input);close(output);
end.