#include <bits/stdc++.h>
using namespace std;
int n, m, mr[] = {-1, 0, 1, 0}, mc[] = {0, 1, 0, -1};
string st[1011];
int vis[1011][1011];
bool cycl;
bool check(int i, int j) {
  vis[i][j] = 1;
  for (int z = 0; z < 4; z++) {
    int nr = mr[z] + i, nc = mc[z] + j;
    if (nr >= n || nc >= m || nr < 0 || nc < 0) continue;
    bool f = 0;
    if (st[i][j] == 'D' && st[nr][nc] == 'I') f = 1;
    if (st[i][j] == 'I' && st[nr][nc] == 'M') f = 1;
    if (st[i][j] == 'M' && st[nr][nc] == 'A') f = 1;
    if (st[i][j] == 'A' && st[nr][nc] == 'D') f = 1;
    if (f == 0) continue;
    if (vis[nr][nc] == 1) {
      return 1;
    }
    if (vis[nr][nc] == 2) continue;
    if (check(nr, nc)) return 1;
  }
  vis[i][j] = 2;
  return 0;
}
int dp[1011][1011];
int rec(int i, int j) {
  if (~dp[i][j]) return dp[i][j];
  int ret = 0;
  for (int z = 0; z < 4; z++) {
    int nr = mr[z] + i, nc = mc[z] + j;
    if (nr >= n || nc >= m || nr < 0 || nc < 0) continue;
    bool f = 0;
    if (st[i][j] == 'D' && st[nr][nc] == 'I') f = 1;
    if (st[i][j] == 'I' && st[nr][nc] == 'M') f = 1;
    if (st[i][j] == 'M' && st[nr][nc] == 'A') f = 1;
    if (st[i][j] == 'A' && st[nr][nc] == 'D') f = 1;
    if (f == 0) continue;
    int tmp = 0;
    if (st[nr][nc] == 'A')
      tmp = 1 + rec(nr, nc);
    else
      tmp = rec(nr, nc);
    ret = max(ret, tmp);
  }
  return dp[i][j] = ret;
}
int main() {
  cin >> n >> m;
  memset((dp), (-1), sizeof(dp));
  for (int i = 0; i < n; i++) cin >> st[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (vis[i][j] == 0 && st[i][j] == 'D') {
        if (check(i, j)) {
          printf("Poor Inna!");
          return 0;
        }
      }
  int mx = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (st[i][j] == 'D') {
        mx = max(mx, rec(i, j));
      }
  if (mx == 0)
    printf("Poor Dima!");
  else
    cout << mx << endl;
  return 0;
}
