# 1025번. 제곱수 찾기
importmathN,M=map(int,input().split())box=[[0for_inrange(M)]for_inrange(N)]foriinrange(N):box[i]=list(map(int,input()))result=-1forninrange(N):forminrange(M):forweight_ninrange(-N,N):forweight_minrange(-M,M):ifweight_n==0andweight_m==0:continuestep=0x=ny=mvalue=''while(0<=x<N)and(0<=y<M):value+=str(box[x][y])step+=1value_int=int(''.join(value))value_sqrt=math.sqrt(value_int)value_decimal=value_sqrt-int(value_sqrt)ifvalue_decimal==0andvalue_int>result:result=value_intx=n+step*weight_ny=m+step*weight_mprint(result)