#include <bits/stdc++.h>
using namespace std;
int n, m, visit[1002][1002], answer[1002][1002];
int flag = 0, maxanswer = 0, count1 = 1, count2 = 1;
char array1[1010][1010];
int dfs(int i, int j, char next) {
  int ans = 0, ans1 = 0;
  char next1;
  if (next == 'D')
    next1 = 'I';
  else if (next == 'I')
    next1 = 'M';
  else if (next == 'M')
    next1 = 'A';
  else
    next1 = 'D';
  if (next == 'D') ans++;
  if (next == 'I' and visit[i][j] == count2) {
    answer[i][j] = 1e9;
    return 1e9;
  }
  if (next == 'I' and visit[i][j] != 0) {
    return answer[i][j];
  }
  if (next == 'I' and visit[i][j] == 0) {
    visit[i][j] = count2;
  }
  if (array1[i + 1][j] == next) {
    ans1 = max(dfs(i + 1, j, next1), ans1);
  }
  if (array1[i - 1][j] == next) {
    ans1 = max(dfs(i - 1, j, next1), ans1);
  }
  if (array1[i][j + 1] == next) {
    ans1 = max(dfs(i, j + 1, next1), ans1);
  }
  if (array1[i][j - 1] == next) {
    ans1 = max(dfs(i, j - 1, next1), ans1);
  }
  if (ans1 != 1e9)
    ans += ans1;
  else
    ans = ans1;
  answer[i][j] = ans;
  if (next == 'I') visit[i][j] = ++count1;
  return ans;
}
int main() {
  cin >> n >> m;
  memset(array1, 'a', sizeof(array1));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> array1[i][j];
    }
  }
  queue<pair<int, int> > q;
  queue<int> q1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) visit[i][j] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (array1[i][j] == 'D' and visit[i][j] == 0) {
        answer[i][j] = dfs(i, j, 'I');
        maxanswer = max(maxanswer, answer[i][j]);
        count1++;
        count2 = count1;
      } else if (array1[i][j] == 'D') {
        maxanswer = max(answer[i][j], maxanswer);
      }
    }
  }
  if (maxanswer == 1e9)
    cout << "Poor Inna!\n";
  else if (maxanswer == 0)
    cout << "Poor Dima!\n";
  else
    cout << maxanswer << "\n";
}
