#include <bits/stdc++.h>
using namespace std;
const int nm = 1005;
int n, k, m, t, MAX = 0;
char a[nm][nm];
bool check[nm][nm];
int Max[nm][nm];
int Dx[nm * nm], Dy[nm * nm], nD;
int p[4] = {0, 0, -1, 1}, q[4] = {1, -1, 0, 0};
char s[] = " DIMA";
int Find(int x, int y, int st, int sl) {
  int i, j;
  if (check[x][y]) {
    cout << "Poor Inna!";
    exit(0);
  }
  if (Max[x][y] != 0) {
    return Max[x][y];
  }
  if (st > 4) st = 1;
  check[x][y] = 1;
  int didc = 0;
  for (i = 0; i < 4; i++) {
    if (a[x + p[i]][y + q[i]] == s[st])
      didc = max(didc, Find(x + p[i], y + q[i], st + 1, sl + 1));
  }
  check[x][y] = 0;
  Max[x][y] = didc + 1;
  return Max[x][y];
}
int main() {
  int i, j, x, y, z, w;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%s", &a[i]);
  for (i = 1; i <= n; i++)
    for (j = m; j >= 1; j--) a[i][j] = a[i][j - 1];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (a[i][j] == 'D') {
        Dx[++nD] = i;
        Dy[nD] = j;
      }
  while (nD > 0) {
    x = Dx[nD];
    y = Dy[nD];
    nD--;
    z = Find(x, y, 2, 0);
    if (z > MAX) MAX = z;
  }
  MAX = MAX / 4;
  if (MAX == 0)
    cout << "Poor Dima!";
  else
    cout << MAX;
  return 0;
}
