#include <bits/stdc++.h>
const long long mod = (long long)1e9 + 7;
using namespace std;
long long n, m;
long long visited[1001][1001];
string str[1001];
long long ans[1001][1001];
long long x[] = {1, 0, -1, 0};
long long y[] = {0, 1, 0, -1};
long long st[1001][1001];
bool check(long long i, long long j) {
  if (i < 0 or j < 0 or i >= n or j >= m) return false;
  return true;
}
bool foo;
void dfs(long long i, long long j) {
  visited[i][j] = 1;
  st[i][j] = 1;
  if (str[i][j] == 'A') ans[i][j] = 1;
  char ch;
  if (str[i][j] == 'D')
    ch = 'I';
  else if (str[i][j] == 'I')
    ch = 'M';
  else if (str[i][j] == 'M')
    ch = 'A';
  else
    ch = 'D';
  long long mx = 0;
  for (long long p = 0; p < 4; p++) {
    if (!check(i + x[p], j + y[p])) continue;
    if (str[i + x[p]][j + y[p]] != ch) continue;
    if (!visited[i + x[p]][j + y[p]]) {
      dfs(i + x[p], j + y[p]);
    }
    if (st[i + x[p]][j + y[p]]) {
      foo = false;
      return;
    }
    mx = max(ans[i + x[p]][j + y[p]], mx);
  }
  ans[i][j] += mx;
  st[i][j] = 0;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> str[i];
  foo = true;
  long long mx = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (str[i][j] == 'D' and !visited[i][j]) {
        dfs(i, j);
        mx = max(mx, ans[i][j]);
      }
    }
  }
  if (!foo) {
    cout << "Poor Inna!\n";
  } else {
    (mx == 0) ? cout << "Poor Dima!" : cout << mx;
  }
  return 0;
}
