#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct abd
{
int x;
int y,step;
} cur,nxt;
queue<abd>que;
int mp[][];
bool v[][];
int moe[] = {,,-,,};
int n,m,li[];
int tox,toy;
void bfs(int xx,int xy)
{
while(!que.empty())que.pop();
memset(v,,sizeof(v));
cur.x=xx;
cur.y=xy;
cur.step=;
que.push(cur);
v[xx][xy]=;
while(!que.empty())
{
cur=que.front();
que.pop();
for(int i=; i<; i++)
{
int xxx=cur.x+moe[i];
int yyy=cur.y+moe[i+];
if(xxx==tox&&yyy==toy)
{
cout<<cur.step+<<endl;
return;
}
else if(xxx<=n&&xxx>=&&yyy>=&&yyy<=m&&!mp[xxx][yyy]&&!v[xxx][yyy])
{
nxt.x=xxx;
nxt.y=yyy;
nxt.step=cur.step+;
v[xxx][yyy]=;
que.push(nxt);
}
}
}
cout<<-<<endl;
}
int main() {
string a;
while(cin>>n>>m)
{
if(n==&&m==)break;
for(int i=; i<=n; i++)
{
cin>>a;
for(int j=; j<a.size(); j++)
{
switch(a[j])
{
case '.' :mp[i][j+]=;
break;
case '#' :mp[i][j+]=; break;
case '*' :mp[i][j+]=;tox=i;toy=j+;break;
case '@' :mp[i][j+]=;li[]=i;li[]=j+;break;
}
}
}
bfs(li[],li[]);
}
return ;
}