while (tt > hh) { auto t = q[++ hh]; int xy = t.first, dist = t.second;
int x = xy / m, y = xy % m; for (int i = 0; i < 4; ++ i) { int a = x + dx[i], b = y + dy[i]; if (a >= 0 && a < n && b >= 0 && b < m && !st[a][b] && g[a][b] != '#') { if (g[a][b] == '*') return dist + 1; st[a][b] = true; q[++ tt] = {a * m + b, dist + 1}; } } }
return-1; }
intmain() { ios::sync_with_stdio(false);
while (cin >> n >> m, n) {
memset(st, false, sizeof st);
for (int i = 0; i < n; ++ i) for (int j = 0; j < m; ++ j) { cin >> g[i][j]; if (g[i][j] == '@') start = i * m + j, st[i][j] = true; }