#include <bits/stdc++.h>
using namespace std;
template <class T>
T Max(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
T Min(T &a, T b) {
  if (a > b) a = b;
}
struct info {
  int r, c;
} orig[1001][1001];
int a_x[] = {1, 0, 0, -1};
int a_y[] = {0, -1, 1, 0};
char grid[1005][1005];
int visit[1005][1005];
int dp[1005][1005];
int n, m;
int res = 0;
int inf = 0;
int check = 0;
char ch[10];
int first = 0;
int dfs(int x, int y, int or1, int or2, int pos) {
  if (inf) return 0;
  if (visit[x][y] == 1) {
    inf = 1;
    return 0;
  }
  if (visit[x][y] == 2) return dp[x][y];
  int i, j;
  int out = 0;
  if (pos % 4 == 3) out = 1;
  visit[x][y] = 1;
  int maggoma = 0;
  for (i = 0; i <= 3; i++) {
    int e = x + a_x[i];
    int f = y + a_y[i];
    int q = out;
    if (e >= 1 && e <= n && f >= 1 && f <= m &&
        grid[e][f] == ch[(pos + 1) % 4]) {
      q += dfs(e, f, or1, or2, (pos + 1) % 4);
    }
    maggoma = max(maggoma, q);
  }
  visit[x][y] = 2;
  return dp[x][y] = maggoma;
}
int main() {
  int i, j;
  cin >> n >> m;
  getchar();
  ch[0] = 'D', ch[1] = 'I', ch[2] = 'M', ch[3] = 'A';
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) scanf("%c", &grid[i][j]);
    getchar();
  }
  int z = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      inf = 0;
      if (grid[i][j] == 'D' && !visit[i][j]) {
        int t = dfs(i, j, i, j, 0);
        res = max(res, t);
        if (inf) {
          cout << "Poor Inna!";
          return 0;
        }
      }
    }
  }
  if (res == 0)
    cout << "Poor Dima!";
  else
    cout << res;
  cout << endl;
  return 0;
}
