#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
int n, m, c;
char mat[1111][1111];
int vis[1001][1001];
map<char, char> nxt;
int dp[1001][1001];
bool dfs(int x, int y) {
  vis[x][y] = 1;
  int &ans = dp[x][y];
  char next = nxt[mat[x][y]];
  for (int a, b, i = 0; i < 4; ++i) {
    a = dx[i] + x;
    b = dy[i] + y;
    if (a < 0 || b < 0 || a >= n || b >= m || mat[a][b] != next) continue;
    if (vis[a][b] != 2 && (vis[a][b] == 1 || dfs(a, b))) return 1;
    ans = max(ans, dp[a][b]);
  }
  if (mat[x][y] == 'A') ans++;
  vis[x][y] = 2;
  return 0;
}
int main(int argc, char **argv) {
  nxt['D'] = 'I';
  nxt['I'] = 'M';
  nxt['M'] = 'A';
  nxt['A'] = 'D';
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) scanf(" %c", mat[i] + j);
  int ans = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (mat[i][j] == 'D' && !vis[i][j]) {
        if (dfs(i, j)) {
          puts("Poor Inna!");
          return 0;
        }
        ans = max(ans, dp[i][j]);
      }
  if (!ans)
    puts("Poor Dima!");
  else
    printf("%d\n", ans);
  return 0;
}
