#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 11, inf = 1e9 + 10;
char ch[4] = {'D', 'I', 'M', 'A'};
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1}, ans = -inf, tans[N][N], n, m;
char c[N][N];
bool mark[N][N], indfs[N][N];
bool isOkay(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }
void calcans(int i, int j, int X, int Y) {
  tans[i][j] = max(tans[i][j], tans[X][Y]);
}
void dfs(int i, int j, int ind) {
  indfs[i][j] = true;
  mark[i][j] = true;
  bool r = false;
  for (int k = 0; k < 4; k++) {
    int X = i + dx[k], Y = j + dy[k], t = (ind + 1) % 4;
    if (!isOkay(X, Y) || c[X][Y] != ch[t]) continue;
    r = true;
    if (indfs[X][Y]) {
      tans[i][j] = inf;
      continue;
    }
    if (mark[X][Y]) {
      calcans(i, j, X, Y);
      continue;
    }
    dfs(X, Y, t);
    calcans(i, j, X, Y);
  }
  if (!r && c[i][j] != 'A')
    tans[i][j] = -inf;
  else if (c[i][j] == 'A')
    tans[i][j]++;
  indfs[i][j] = false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> c[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (c[i][j] != 'D' || mark[i][j]) continue;
      dfs(i, j, 0);
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) ans = max(ans, tans[i][j]);
  if (ans <= 0)
    cout << "Poor Dima!";
  else if (ans >= inf)
    cout << "Poor Inna!";
  else
    cout << ans;
}
