#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 10 * 100 + 19;
const int inf = 2e9 + 19;
int n, m, ans = 0, cnt[MAX_N][MAX_N];
char C[] = {'D', 'I', 'M', 'A'};
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
string G[MAX_N];
bool mark[MAX_N][MAX_N];
bool isValid(int xx, int yy) {
  return (xx < n && yy < m && yy >= 0 && xx >= 0);
}
int dfs(int x, int y, int c) {
  if (~cnt[x][y]) return cnt[x][y];
  cnt[x][y] = 0;
  mark[x][y] = true;
  char cc = C[(c + 1) % 4];
  for (int X = 0; X < 4; X++) {
    int nx = x + dx[X], ny = y + dy[X];
    if (!isValid(nx, ny) || G[nx][ny] != cc) continue;
    if (mark[nx][ny]) {
      cout << "Poor Inna!";
      exit(0);
    }
    cnt[x][y] = max(dfs(nx, ny, (c + 1) % 4), cnt[x][y]);
  }
  cnt[x][y] += (c == 3);
  mark[x][y] = false;
  return cnt[x][y];
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> G[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cnt[i][j] = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!~cnt[i][j] && G[i][j] == 'D') {
        dfs(i, j, 'D');
        ans = max(ans, cnt[i][j]);
      }
    }
  }
  if (!ans)
    cout << "Poor Dima!";
  else
    cout << ans;
  return (0);
}
