#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef pair PI; #define REP(i,n) for (int i=0; i=0; i--) #define FOREACH(it,a) for (__typeof(a.begin()) it=a.begin(); it!=a.end(); it++) int R, C; bitset<20> oper(bitset<20> a, bitset<20> b) { bitset<20> res = a ^ b ^ (b<<1) ^ (b>>1); if (res[C]) res[C] = false; return res; } int main() { char x[50][50]; bitset<20> a[32], b[32]; while (scanf("%d %d", &R, &C) == 2) { if (R == 0 && C == 0) break; REP(i,32) { a[i].reset(); b[i].reset(); } REP(i,R) { scanf("%s", x[i]); REP(j,C) a[i][j] = (x[i][j] == 'X'); } int s = 1<(i); b[1] = oper(a[0], b[0]); FOR(j,1,R) { b[j+1] = oper(a[j]^b[j-1], b[j]); } int m = 0; REP(j,R) m += b[j].count(); if (b[R].count() == 0) res = min(res, m); } if (res != R*C+47) printf("You have to tap %d tiles.\n", res); else printf("Damaged billboad.\n"); } }