#include <bits/stdc++.h>
using namespace std;
bool visited[1009][1009], restack[1009][1009];
int ans[1009][1009];
int n, m;
int dirx[] = {-1, 1, 0, 0};
int diry[] = {0, 0, -1, 1};
char a[1009][1009];
char name[] = "DIMA";
bool cycle(int x, int y, int c) {
  visited[x][y] = true;
  restack[x][y] = true;
  int c2 = (c + 1) % 4;
  for (int i = 0; i < 4; i++) {
    int tx = x + dirx[i];
    int ty = y + diry[i];
    if (tx >= 0 && tx < n && ty >= 0 && ty < m && a[tx][ty] == name[c2]) {
      if (!visited[tx][ty] && cycle(tx, ty, c2))
        return true;
      else if (restack[tx][ty])
        return true;
    }
  }
  restack[x][y] = false;
  return false;
}
int solve(int x, int y, int c) {
  if (ans[x][y] != -1) return ans[x][y];
  ans[x][y] = 0;
  int c2 = (c + 1) % 4;
  for (int i = 0; i < 4; i++) {
    int tx = x + dirx[i];
    int ty = y + diry[i];
    if (tx >= 0 && tx < n && ty >= 0 && ty < m && a[tx][ty] == name[c2]) {
      ans[x][y] = max(ans[x][y], solve(tx, ty, c2));
    }
  }
  if (c == 3) ans[x][y]++;
  return ans[x][y];
}
int main() {
  int i, j, k;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) ans[i][j] = -1;
  }
  int ansmax = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] == 'D') {
        if (cycle(i, j, 0)) {
          cout << "Poor Inna!" << endl;
          return 0;
        } else {
          ansmax = max(ansmax, solve(i, j, 0));
        }
      }
    }
  }
  if (ansmax == 0)
    cout << "Poor Dima!" << endl;
  else
    cout << ansmax << endl;
}
