#include <bits/stdc++.h>
using namespace std;
const int INF = 2000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
const int maxn = 1100;
int n, m, sz, ans, dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}, dp[maxn][maxn],
                   used[maxn][maxn];
char a[maxn][maxn];
pair<int, int> b[maxn * maxn];
bool check(int x, int y, int u, int v) {
  if (a[x][y] == 'D' && a[u][v] == 'I') return true;
  if (a[x][y] == 'I' && a[u][v] == 'M') return true;
  if (a[x][y] == 'M' && a[u][v] == 'A') return true;
  if (a[x][y] == 'A' && a[u][v] == 'D') return true;
  return false;
}
void dfs(int x, int y) {
  used[x][y] = 1;
  dp[x][y] = 0;
  if (a[x][y] == 'A') dp[x][y] = 1;
  for (int i = 0; i < 4; ++i)
    if (x + dx[i] > 0 && x + dx[i] <= n && y + dy[i] > 0 && y + dy[i] <= m) {
      if (!check(x, y, x + dx[i], y + dy[i])) continue;
      if (used[x + dx[i]][y + dy[i]] == 1) {
        cout << "Poor Inna!";
        exit(0);
      }
      if (!used[x + dx[i]][y + dy[i]]) dfs(x + dx[i], y + dy[i]);
      dp[x][y] = max(dp[x][y], dp[x + dx[i]][y + dy[i]] + (a[x][y] == 'A'));
    }
  used[x][y] = 2;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == 'D') b[sz++] = make_pair(i, j);
    }
  for (int i = 0; i < sz; ++i) {
    if (!used[b[i].first][b[i].second]) dfs(b[i].first, b[i].second);
    ans = max(ans, dp[b[i].first][b[i].second]);
  }
  if (!ans)
    cout << "Poor Dima!";
  else
    cout << ans;
  return 0;
}
