#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 5;
int n, m;
char grid[MAX][MAX];
bool visited[MAX][MAX];
int memo[MAX][MAX];
bool EH_NOIS = false;
inline bool inside(int x, int y) {
  return x >= 1 && x <= n && y >= 1 && y <= m;
}
inline char nxt(char c) {
  if (c == 'D') return 'I';
  if (c == 'I') return 'M';
  if (c == 'M') return 'A';
  return 'D';
}
inline int roll(int x, int y) {
  if (EH_NOIS) {
    return 0;
  }
  if (visited[x][y] && memo[x][y] == -1) {
    EH_NOIS = true;
    return 0;
  }
  if (~memo[x][y]) {
    return memo[x][y];
  }
  visited[x][y] = true;
  char c = grid[x][y];
  int ans = 0;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      if ((i || j) && (!i || !j)) {
        int ni = x + i;
        int nj = y + j;
        if (inside(ni, nj)) {
          if (grid[ni][nj] == nxt(c)) {
            ans = max(ans, roll(ni, nj));
          }
        }
      }
    }
  }
  return memo[x][y] = ans + (grid[x][y] == 'A');
}
int main() {
  scanf("%d %d%*c", &n, &m);
  for (int i = int(1); i < int(n + 1); i++) {
    for (int j = int(1); j < int(m + 1); j++) {
      scanf("%c", &grid[i][j]);
    }
    scanf("%*c");
  }
  memset(visited, false, sizeof visited);
  memset(memo, -1, sizeof memo);
  int ans = 0;
  for (int i = int(1); i < int(n + 1); i++) {
    for (int j = int(1); j < int(m + 1); j++) {
      if (grid[i][j] == 'D') {
        ans = max(ans, roll(i, j));
      }
    }
  }
  if (EH_NOIS) {
    cout << "Poor Inna!\n";
  } else if (ans == 0) {
    cout << "Poor Dima!\n";
  } else {
    cout << ans << '\n';
  }
  return 0;
}
