public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());
        s = new String[n];
        for(int i=0; i<n; i++){
            s[i] = br.readLine();
        }
        best = new int[n][m];
        visited = new boolean[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++) best[i][j] = -1;
        }
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(best[i][j]<0 && s[i].charAt(j)=='D'){
                    calc(i,j);
                }
            }
        }
        if(result == 0) System.out.println("Poor Dima!"); else
        if(result == INF) System.out.println("Poor Inna!"); else System.out.println(result);
    }