#include <bits/stdc++.h>
using namespace std;
char c[1010][1010];
vector<int> e[1000010];
int dp[1000010];
int n, m;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
bool pd(int x, int y) {
  if (x < 0 || y < 0) return false;
  return x < n && y < m;
}
int dfs(int x) {
  int y, re = 0;
  dp[x] = -2;
  for (int i = 0; i < (int)e[x].size(); i++) {
    y = e[x][i];
    if (dp[y] == -2) return dp[x] = 1 << 30;
    if (dp[y] == -1) dfs(y);
    re = max(re, dp[y]);
  }
  return dp[x] = re + 1;
}
int main() {
  int i, j, k, x, y;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", c[i]);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      for (k = 0; k < 4; k++) {
        x = i + dx[k];
        y = j + dy[k];
        if (!pd(x, y)) continue;
        if (c[i][j] == 'D' && c[x][y] == 'I') e[i * m + j].push_back(x * m + y);
        if (c[i][j] == 'I' && c[x][y] == 'M') e[i * m + j].push_back(x * m + y);
        if (c[i][j] == 'M' && c[x][y] == 'A') e[i * m + j].push_back(x * m + y);
        if (c[i][j] == 'A' && c[x][y] == 'D') e[i * m + j].push_back(x * m + y);
      }
      dp[i * m + j] = -1;
    }
  }
  int ans = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (c[i][j] == 'D') {
        ans = max(ans, dfs(i * m + j));
      }
    }
  }
  if (ans > n * m)
    printf("Poor Inna!\n");
  else if (ans < 4)
    printf("Poor Dima!\n");
  else
    printf("%d\n", ans / 4);
  return 0;
}
