#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
const int INF = 1e9;
const int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const char *name = "DIMA";
int N, M, res, cnt;
int dn[MAXN][MAXN];
char ar[MAXN][MAXN];
int dfs(int i, int j, int ind) {
  int &rev = dn[i][j];
  if (rev > -1) return rev;
  rev = -2;
  int mx = 0;
  for (int k = 0; k < 4; k++) {
    int ni = i + dir[k][0];
    int nj = j + dir[k][1];
    if (1 <= ni && 1 <= nj && ni <= N && nj <= M && ar[ni][nj] == name[ind]) {
      if (dn[ni][nj] == -2)
        return rev = INF;
      else
        mx = max(mx, dfs(ni, nj, (ind + 1) % 4));
    }
  }
  return rev = mx + (ind == 0);
}
int main() {
  scanf("%d%d", &N, &M);
  memset(dn, -1, sizeof dn);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) scanf(" %c", &ar[i][j]);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++, cnt++)
      if (ar[i][j] == 'D') res = max(res, dfs(i, j, 1));
  if (res == 0)
    puts("Poor Dima!");
  else if (res >= INF)
    puts("Poor Inna!");
  else
    printf("%d\n", res);
  return 0;
}
