#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smax(T &x, T y) {
  x = max((x), (y));
}
template <class T>
inline void smin(T &x, T y) {
  x = min((x), (y));
}
const int MOD = 1e9 + 7;
const int SIZE = 1e3 + 10;
const int INF = 0x3f3f3f3f;
int n, m;
vector<string> board;
int di[SIZE][SIZE];
int c[SIZE][SIZE];
bool cycle;
int color;
bool con(char c1, char c2) {
  switch (c1) {
    case 'D':
      return c2 == 'I';
    case 'I':
      return c2 == 'M';
    case 'M':
      return c2 == 'A';
    default:
      return c2 == 'D';
  }
}
int dfs(int i, int j) {
  if (di[i][j] == -2) {
    cycle = true;
    return 0;
  }
  if (di[i][j] != -1) return di[i][j];
  di[i][j] = -2;
  int best = 1;
  int dir[4] = {1, 0, -1, 0};
  for (int d = 0; d < (4); ++d) {
    int nexti = i + dir[d];
    int nextj = j + dir[d ^ 1];
    if (nexti < 0 || nexti >= n || nextj < 0 || nextj >= m ||
        !con(board[i][j], board[nexti][nextj]))
      continue;
    smax(best, 1 + dfs(nexti, nextj));
  }
  return di[i][j] = best;
}
int main() {
  if (0) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  while (cin >> n >> m) {
    cycle = false;
    color = 0;
    memset((c), 0, sizeof((c)));
    board.resize(n);
    for (int i = 0; i < (n); ++i) cin >> board[i];
    memset((di), -1, sizeof((di)));
    memset((c), -1, sizeof((c)));
    int ans = -1;
    for (int i = 0; i < (n); ++i)
      for (int j = 0; j < (m); ++j) {
        if (board[i][j] == 'D') smax(ans, dfs(i, j));
      }
    for (int i = 0; i < (n); ++i) {
      for (int j = 0; j < (m); ++j) {
      }
    }
    if (cycle) {
      printf("Poor Inna!\n");
    } else if (ans < 4) {
      printf("Poor Dima!\n");
    } else {
      printf("%d\n", ans / 4);
    }
  }
  return 0;
}
