#include <bits/stdc++.h>
using namespace std;
char a[1003][1003];
bool vis[1003][1003];
int dirx[] = {0, 0, -1, 1}, ans, diry[] = {1, -1, 0, 0}, dp[1003][1003], n, m;
string s = "DIMA";
int solve(int x, int y, int ind) {
  if (vis[x][y]) cout << "Poor Inna!", exit(0);
  if (dp[x][y] != -1) return dp[x][y];
  dp[x][y] = 0;
  vis[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int dx = x + dirx[i], dy = y + diry[i];
    if (dx > -1 && dx < n && dy > -1 && dy < m && s[ind % 4] == a[dx][dy])
      dp[x][y] = max(dp[x][y], solve(dx, dy, ind + 1));
  }
  dp[x][y] += (a[x][y] == 'A');
  vis[x][y] = false;
  return dp[x][y];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == 'D') ans = max(ans, solve(i, j, 1));
  if (!ans)
    cout << "Poor Dima!";
  else
    cout << ans;
  return 0;
}
