def dfs(i, j, map)
  map[i][j] = '0'

  dfs(i + 1, j, map) if map[i + 1]    && map[i + 1][j] == '1'
  dfs(i - 1, j, map) if i >= 1        && map[i - 1][j] == '1'
  dfs(i, j + 1, map) if map[i][j + 1] && map[i][j + 1] == '1'
  dfs(i, j - 1, map) if j >= 1        && map[i][j - 1] == '1'
end

def show(map)
  puts
  map.each do |row|
    puts row.join('')
  end
  gets
end

maps = [[]]

gets(nil).each_line do |line|
  line = line.chomp
  if line == ''
    maps.push []
  else
    maps.last.push line.split('')
  end
end

maps.each do |map|
  ans = 0
  0.upto(map.size - 1) do |i|
    0.upto(map[i].size - 1) do |j|
      if map[i][j] == '1'
        dfs(i, j, map)
        ans += 1
      end
    end
  end
  puts ans
end