#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
string table[1010];
int dp[1010][1010];
bool visit[1010][1010];
char nxt[200];
string s = "DIMA";
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int n, m;
int dfs(int i, int j) {
  if (visit[i][j]) return INF;
  if (dp[i][j] >= 0) return dp[i][j];
  visit[i][j] = 1;
  int res = 0;
  for (int d = 0; d < (4); d++) {
    int ni = i + dy[d], nj = j + dx[d];
    if (ni < 0 || ni >= n || nj < 0 || nj >= m) continue;
    if (table[ni][nj] != nxt[table[i][j]]) continue;
    if (visit[ni][nj])
      res = INF;
    else
      res = max(res, dfs(ni, nj));
  }
  visit[i][j] = 0;
  return dp[i][j] = min(INF, res + 1);
}
int main() {
  for (int i = 0; i < (4); i++) nxt[s[i]] = s[(i + 1) % 4];
  cin >> n >> m;
  for (int i = 0; i < (n); i++) cin >> table[i];
  int ans = 0;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++)
      if (table[i][j] == 'D') ans = max(ans, dfs(i, j) / 4);
  if (ans >= INF / 4)
    cout << "Poor Inna!" << endl;
  else if (ans == 0)
    cout << "Poor Dima!" << endl;
  else
    cout << ans << endl;
  return 0;
}
