#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e3 + 5;
vector<pair<int, int> > p;
char s[N][N];
int dp[N][N], used[N][N];
int dx[5] = {0, 1, 0, -1}, dy[5] = {1, 0, -1, 0};
int n, m;
bool f = 0;
char pr(char first) {
  if (first == 'D')
    return 'I';
  else if (first == 'I')
    return 'M';
  else if (first == 'M')
    return 'A';
  else
    return 'D';
}
bool ok(int first, int second) {
  return first < n && second < m && first >= 0 && second >= 0;
}
void dfs(int first, int second) {
  if (f) return;
  used[first][second] = 1;
  for (int i = 0; i < 4; i++) {
    int tox = first + dx[i], toy = second + dy[i];
    if (!ok(tox, toy) || pr(s[first][second]) != s[tox][toy]) continue;
    if (used[tox][toy] == 2) {
      dp[first][second] = max(dp[first][second], 1 + dp[tox][toy]);
      continue;
    }
    if (used[tox][toy] == 1) {
      f = 1;
      return;
    }
    dfs(tox, toy);
    dp[first][second] = max(dp[first][second], 1 + dp[tox][toy]);
  }
  used[first][second] = 2;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) dp[i][j] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (!used[i][j] && s[i][j] == 'D') dfs(i, j);
  if (f) return cout << "Poor Inna!\n", 0;
  int mx = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) mx = max(mx, dp[i][j]);
  mx /= 4;
  if (mx == 0)
    cout << "Poor Dima!\n";
  else
    cout << mx << endl;
  return 0;
}
