#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int Mod = 1e9 + 7;
const int N = 1e3 + 100;
const int M = 1e6 + 100;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
inline long long dpow(long long a, long long b) {
  long long r = 1, t = a;
  while (b) {
    if (b & 1) r = (r * t) % Mod;
    b >>= 1;
    t = (t * t) % Mod;
  }
  return r;
}
inline long long fpow(long long a, long long b) {
  long long r = 1, t = a;
  while (b) {
    if (b & 1) r = (r * t);
    b >>= 1;
    t = (t * t);
  }
  return r;
}
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
vector<int> G[M];
int in[M], dp[M], n, m;
char str[N][N];
int vis[M], cnt;
int Num(int x, int y) { return (x - 1) * m + y; }
void Add(int u, int v) { G[u].push_back(v); }
void Merge(int x, int y) {
  int u = Num(x, y);
  for (int i = 0; i < 4; i++) {
    int xx = x + dir[i][0];
    int yy = y + dir[i][1];
    if (xx < 0 || xx > n || yy < 0 || yy > m) continue;
    int v = Num(xx, yy);
    if (str[x][y] == 'D' && str[xx][yy] == 'I')
      Add(u, v);
    else if (str[x][y] == 'I' && str[xx][yy] == 'M')
      Add(u, v);
    else if (str[x][y] == 'M' && str[xx][yy] == 'A')
      Add(u, v);
    else if (str[x][y] == 'A' && str[xx][yy] == 'D')
      Add(u, v);
  }
}
bool DFS(int x) {
  if (vis[x] == 1) return true;
  if (vis[x] == -1) return false;
  vis[x] = 1;
  cnt++;
  for (auto v : G[x]) {
    in[v]++;
    if (DFS(v)) return true;
  }
  vis[x] = -1;
  return false;
}
void Topsort() {
  queue<int> q;
  for (int i = 1; i <= n * m; i++)
    if (vis[i] && !in[i]) q.push(i), dp[i] = 1;
  int ans = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    ans = max(ans, dp[u]);
    for (auto v : G[u]) {
      in[v]--;
      dp[v] = max(dp[v], dp[u] + 1);
      if (!in[v]) q.push(v);
    }
  }
  if (ans < 4)
    puts("Poor Dima!");
  else
    printf("%d\n", ans / 4);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      Merge(i, j);
      if (str[i][j] == 'D') dp[Num(i, j)] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == 'D' && DFS(Num(i, j))) puts("Poor Inna!"), exit(0);
    }
  }
  Topsort();
  return 0;
}
