#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
const int maxn = 1010;
const int maxm = 1e6 + 10;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char mp[maxn][maxn], com[] = "DIMA";
int dp[maxn][maxn];
int n, m;
int dfs(int x, int y, int cnt) {
  if (dp[x][y] != -1) return dp[x][y];
  dp[x][y] = 0x3f3f3f3f;
  int t = 0;
  cnt = (1 + cnt) % 4;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (xx >= 0 && xx < n && yy >= 0 && yy < m && mp[xx][yy] == com[cnt]) {
      t = max(t, dfs(xx, yy, cnt));
    }
  }
  dp[x][y] = ++t;
  return t;
}
int main() {
  ios_base::sync_with_stdio(0);
  while (cin >> n >> m) {
    int Max = 0;
    for (int i = 0; i < n; i++) cin >> mp[i];
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (mp[i][j] == 'D') Max = max(Max, dfs(i, j, 0));
    if (Max < 4)
      cout << "Poor Dima!\n";
    else if (Max >= 0x3f3f3f3f)
      cout << "Poor Inna!\n";
    else
      cout << Max / 4 << endl;
  }
  return 0;
}
