#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int d[int(1e3) + 5][int(1e3) + 5], n, m, res, vis[int(1e3) + 5][int(1e3) + 5];
char s[int(1e3) + 5][int(1e3) + 5];
bool check;
inline int dfs(int x, int y) {
  if (vis[x][y] == 2) return d[x][y];
  if (vis[x][y] == 1) {
    check = true;
    return 0;
  }
  vis[x][y] = 1;
  int res = 0, current = 0;
  if (s[x][y] == 'A') res++, current++;
  char next;
  if (s[x][y] == 'D')
    next = 'I';
  else if (s[x][y] == 'I')
    next = 'M';
  else if (s[x][y] == 'M')
    next = 'A';
  else
    next = 'D';
  for (int i = 0; i < 4; i++) {
    int uu = x + dx[i];
    int vv = y + dy[i];
    if (uu < 1 || uu > n || vv < 1 || vv > m) continue;
    if (s[uu][vv] == next) res = max(res, current + dfs(uu, vv));
  }
  vis[x][y] = 2;
  return d[x][y] = res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (!vis[i][j] && s[i][j] == 'D') res = max(res, dfs(i, j));
  if (check) {
    printf("Poor Inna!");
  } else if (!res) {
    printf("Poor Dima!");
  } else
    printf("%d", res);
}
