#include <bits/stdc++.h>
using namespace std;
char my[1009][1009];
int ic[] = {1, -1, 0, 0};
int jc[] = {0, 0, 1, -1};
char ch[] = {"DIMA"};
int n, m;
bool valid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
const int inf = 1e9 + 7;
int dp[1009][1009];
int dfs(int x, int y) {
  int idx = 0;
  for (int i = 0; i < 4; ++i)
    if (ch[i] == my[x][y]) idx = i;
  int s = 0;
  dp[x][y] = inf;
  for (int i = 0; i < 4; ++i) {
    int x1 = x + ic[i], y1 = y + jc[i];
    if (valid(x1, y1) && my[x1][y1] == ch[(idx + 1) % 4]) {
      if (dp[x1][y1])
        s = max(s, dp[x1][y1]);
      else {
        int h = dfs(x1, y1);
        s = max(s, h);
      }
      s = min(s, inf);
    }
  }
  s = min(s + 1, inf);
  dp[x][y] = s;
  return s;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", my[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (dp[i][j] == 0 && my[i][j] == 'D') dfs(i, j);
  int mx = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) mx = max(mx, dp[i][j]);
  if (mx == inf)
    printf("Poor Inna!\n");
  else if (mx < 4)
    printf("Poor Dima!\n");
  else
    printf("%d\n", mx / 4);
}
