#include <bits/stdc++.h>
using namespace std;
const int fx[] = {1, -1, 0, 0};
const int fy[] = {0, 0, 1, -1};
const int N = 1005;
const int S = N * N;
int n, m, e, cur, t;
int h[S], ne[S * 4], po[S * 4], a[N][N], b[N][N], q[S], d[S], f[S];
int oo[256];
char o[N];
void link(int x, int y) {
  ++e;
  ne[e] = h[x];
  po[e] = y;
  h[x] = e;
  ++d[y];
}
void go(int x, int y, int d) {
  if (d == 5) {
    if (b[x][y]) link(b[x][y], cur);
    return;
  }
  if (a[x][y] != d) return;
  if (d == 4) {
    f[cur] = 1;
  }
  for (int i = 0; i < 4; ++i) go(x + fx[i], y + fy[i], d + 1);
}
int topo() {
  int st = 0, ed = 0;
  for (int i = 1; i <= t; ++i)
    if (!d[i]) q[ed++] = i;
  while (st < ed) {
    int i = q[st++];
    for (int j = h[i], k; k = po[j], j; j = ne[j]) {
      --d[k];
      if (!d[k]) q[ed++] = k;
    }
  }
  if (ed < t) return -1;
  int ans = 0;
  for (int ii = 0, i; i = q[ii], ii < ed; ++ii) {
    ans = max(ans, f[i]);
    for (int j = h[i], k; k = po[j], j; j = ne[j])
      if (f[i] + 1 > f[k]) f[k] = f[i] + 1;
  }
  return ans;
}
int main() {
  oo['D'] = 1;
  oo['I'] = 2;
  oo['M'] = 3;
  oo['A'] = 4;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", o + 1);
    for (int j = 1; j <= m; ++j) {
      a[i][j] = oo[o[j]];
      if (a[i][j] == 1) b[i][j] = ++t;
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      cur = b[i][j];
      go(i, j, 1);
    }
  int ans = topo();
  if (ans == -1)
    puts("Poor Inna!");
  else if (ans == 0)
    puts("Poor Dima!");
  else
    printf("%d\n", ans);
  return 0;
}
