w = (d = DATA.to_a)[0].chomp.size + 2
b = '#' * w + d.map {|s| '#' + s.chomp + '#'}.join + '#' * w
n = 0
while x = b =~ /\./ do
n += 1
a = [x]
while x = a.pop do
[-w-1, -w, -w+1, -1, 1, w-1, w, w+1].map {|s| x + s}.each do |y|
next unless b[y] == '.'
a << y
b[y] = '#'
end
end
end
print n, 'rooms'
__END__
##..##
#.###.
###.#.
...###
dyA9IChkID0gREFUQS50b19hKVswXS5jaG9tcC5zaXplICsgMgpiID0gJyMnICogdyArIGQubWFwIHt8c3wgJyMnICsgcy5jaG9tcCArICcjJ30uam9pbiArICcjJyAqIHcKCm4gPSAwCndoaWxlIHggPSBiID1+IC9cLi8gZG8KCW4gKz0gMQoJYSA9IFt4XQoJd2hpbGUgeCA9IGEucG9wIGRvCgkJWy13LTEsIC13LCAtdysxLCAtMSwgMSwgdy0xLCB3LCB3KzFdLm1hcCB7fHN8IHggKyBzfS5lYWNoIGRvIHx5fAoJCQluZXh0IHVubGVzcyBiW3ldID09ICcuJwoJCQlhIDw8IHkKCQkJYlt5XSA9ICcjJwoJCWVuZAoJZW5kCmVuZAoKcHJpbnQgbiwgJ3Jvb21zJwoKX19FTkRfXwojIy4uIyMKIy4jIyMuCiMjIy4jLgouLi4jIyM=