#include <bits/stdc++.h>
using namespace std;
int x[] = {0, 1, -1, 0};
int y[] = {1, 0, 0, -1};
char mp[1010][1010];
int vis[1010][1010];
int st[1010][1010];
int n, m;
map<char, char> s;
bool f(int x1, int y1) {
  if (x1 >= n || x1 < 0 || y1 >= m || y1 < 0) return false;
  return true;
}
bool cycle = 0;
bool cy[1010][1010];
int dfs(int a, int b) {
  if (cycle) return 0;
  if (cy[a][b]) {
    cycle = 1;
    return 0;
  }
  if (st[a][b]) return st[a][b];
  cy[a][b] = 1;
  int ans = 0;
  int w = 0;
  for (int i = 0; i < 4; ++i) {
    int u1, u2;
    u1 = a + x[i];
    u2 = b + y[i];
    if (mp[a][b] == 'A') w = 1;
    if (f(u1, u2) && s[mp[a][b]] == mp[u1][u2]) {
      if (mp[u1][u2] == 'D') {
        st[u1][u2] = dfs(u1, u2);
        ans = max(ans, st[u1][u2]);
      } else
        ans = max(ans, dfs(u1, u2));
    }
  }
  cy[a][b] = 0;
  return ans + w;
}
int main() {
  while (~scanf("%d %d", &n, &m)) {
    memset(st, 0, sizeof(st));
    cycle = 0;
    for (int i = 0; i < n; ++i) scanf("%s", mp[i]);
    s['D'] = 'I';
    s['I'] = 'M';
    s['M'] = 'A';
    s['A'] = 'D';
    int ans = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) {
        if (mp[i][j] == 'D') {
          ans = max(ans, dfs(i, j));
        }
      }
    if (cycle)
      cout << "Poor Inna!" << endl;
    else if (!ans)
      cout << "Poor Dima!" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
