#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cin>> n>> m;
    char s[n][n];
    int xa, xb, ya, yb;
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < n; j ++)
            {
                cin>>s[i][j];
                if(s[i][j] == 'A')
                {
                    ya = i;
                    xa = j;
                }
                if(s[i][j] == 'B')
                {
                    yb = i;
                    xb = j;
                }
            }
    cout<<-1;
    return 0;
}