#include<bits/stdc++.h>
using namespace std;
char polje[505][505];
int n,m,ax,ay,bx,by;

int main(){
   cin>>n>>m;
   for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
        cin>>polje[i][j];
        if(polje[i][j]=='A'){
            ax=i;
            bx=j;
        }
        else if(polje[i][j]=='B'){
              bx=i;
              by=j;
        }
    }
   }

   cout<<-1<<endl;

  return 0;
}