#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> v;
vector<vector<int> > p;
vector<vector<char> > cols;
inline char gn(char x) {
  if (x == 'D') return 'I';
  if (x == 'I') return 'M';
  if (x == 'M') return 'A';
  if (x == 'A') return 'D';
  return 0;
}
inline bool dfs1(int i, int j) {
  cols[i][j] = 1;
  char ch = gn(v[i][j]);
  const static int delta[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
  for (int k = 0; k < 4; ++k) {
    int a = i + delta[k][0], b = j + delta[k][1];
    if (a < 0 || b < 0 || a >= n || b >= m) continue;
    if (v[a][b] != ch) continue;
    if (cols[a][b] == 1) return true;
    if (cols[a][b] == 0)
      if (dfs1(a, b)) return true;
  }
  cols[i][j] = 2;
  return false;
}
inline int dfs2(int i, int j) {
  if (p[i][j] != -1) return p[i][j];
  int ans = 1;
  char ch = gn(v[i][j]);
  const static int delta[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
  for (int k = 0; k < 4; ++k) {
    int a = i + delta[k][0], b = j + delta[k][1];
    if (a < 0 || b < 0 || a >= n || b >= m) continue;
    if (v[a][b] != ch) continue;
    ans = max(ans, 1 + dfs2(a, b));
  }
  return p[i][j] = ans;
}
int main() {
  cin >> n >> m;
  v.resize(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  p.assign(n, vector<int>(m, -1));
  cols.assign(n, vector<char>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (v[i][j] == 'D' && cols[i][j] == 0 && dfs1(i, j)) {
        puts("Poor Inna!");
        return 0;
      }
  int z = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j)
      if (v[i][j] == 'D') {
        z = max(z, dfs2(i, j));
      }
  }
  z /= 4;
  if (!z) {
    puts("Poor Dima!");
    return 0;
  }
  printf("%d", z);
  return 0;
}
