#include <bits/stdc++.h>
using namespace std;
vector<string> t;
vector<vector<int> > state;
int n, m;
int dfs(int i, int j) {
  if (state[i][j] >= 0) return state[i][j];
  if (state[i][j] == -2) return state[i][j] = 1000000;
  state[i][j] = -2;
  int ans = 0;
  char next;
  if (t[i][j] == 'D') next = 'I';
  if (t[i][j] == 'I') next = 'M';
  if (t[i][j] == 'M') next = 'A';
  if (t[i][j] == 'A') next = 'D';
  if (i && t[i - 1][j] == next) ans = max(ans, dfs(i - 1, j));
  if (j && t[i][j - 1] == next) ans = max(ans, dfs(i, j - 1));
  if (i < n - 1 && t[i + 1][j] == next) ans = max(ans, dfs(i + 1, j));
  if (j < m - 1 && t[i][j + 1] == next) ans = max(ans, dfs(i, j + 1));
  if (t[i][j] == 'A') ans++;
  return state[i][j] = ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  t.resize(n);
  for (int i = 0; i < n; i++) cin >> t[i];
  state.assign(n, vector<int>(m, -1));
  int realans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (t[i][j] == 'D' && state[i][j] == -1) {
        realans = max(realans, dfs(i, j));
      }
    }
  }
  if (realans == 0)
    cout << "Poor Dima!\n";
  else if (realans >= 1000000)
    cout << "Poor Inna!\n";
  else
    cout << realans << '\n';
  return 0;
}
