#include <bits/stdc++.h>
using namespace std;
const double Pi = acos(-1.0);
int N, M;
string txt = "DIMA";
int dp[1001][1001];
char grid[1001][1001];
bool vis[1001][1001], inUse[1001][1001];
bool isPoint(int x, int y) { return x >= 0 && x < M && y >= 0 && y < N; }
int dfs(int x, int y, int prv) {
  static int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  if (txt[(prv + 1) % 4] != grid[y][x]) return 0;
  if (inUse[y][x]) return -1;
  if (vis[y][x]) return dp[y][x];
  vis[y][x] = inUse[y][x] = true;
  int cnt = (grid[y][x] == 'A'), cur = 0;
  for (int i = 0; i < 4; i++) {
    int nxtx = x + dir[i][0];
    int nxty = y + dir[i][1];
    if (isPoint(nxtx, nxty)) {
      int tmp = dfs(nxtx, nxty, (prv + 1) % 4);
      if (tmp == -1) return -1;
      cur = max(cur, tmp);
    }
  }
  inUse[y][x] = false;
  return dp[y][x] = cnt + cur;
}
int main() {
  if (fopen("data.in", "r")) freopen("data.in", "r", stdin);
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) cin >> grid[i][j];
  int result = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (grid[i][j] == 'D' && !vis[i][j]) {
        int tmp = dfs(j, i, -1);
        result = max(result, tmp);
        if (tmp == -1) {
          cout << "Poor Inna!" << endl;
          return 0;
        }
      }
    }
  }
  if (!result)
    cout << "Poor Dima!" << endl;
  else
    cout << result << endl;
  return 0;
}
