#include <bits/stdc++.h>
using namespace std;
const int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};
char G[1003][1003], C[1003][1003];
int n, m, M[1003][1003];
inline char next_char(char &ch) {
  switch (ch) {
    case 'D':
      return 'I';
    case 'I':
      return 'M';
    case 'M':
      return 'A';
  }
  return 'D';
}
int DFS(int x, int y) {
  int c = 0, x1, y1, i;
  C[x][y] = 1;
  for (i = 0; i < 4; ++i) {
    x1 = x + dr[i], y1 = y + dc[i];
    if (x1 >= 0 && x1 < n && y1 >= 0 && y1 < m &&
        G[x1][y1] == next_char(G[x][y])) {
      if (C[x1][y1] == 0)
        c = max(c, DFS(x1, y1));
      else if (C[x1][y1] == 1)
        return 2147483647;
      else
        c = max(c, M[x1][y1]);
    }
  }
  C[x][y] = 2;
  return M[x][y] = (c < 2147483647 ? ((G[x][y] == 'A') + c) : 2147483647);
}
int solve() {
  int c = 0, i, j;
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j)
      if (G[i][j] == 'D' && C[i][j] == 0) c = max(c, DFS(i, j));
  return c;
}
int main() {
  int c, i;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; ++i) scanf("%s", &G[i][0]);
  c = solve();
  if (!c)
    puts("Poor Dima!");
  else if (c == 2147483647)
    puts("Poor Inna!");
  else
    printf("%d\n", c);
  return 0;
}
