#include <bits/stdc++.h>
using namespace std;
int dp[1005][1005], is, js, n, m, mx;
char a[1005][1005];
bool vis[1005][1005];
set<pair<int, int> > s;
bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
int solve(int i, int j) {
  if (s.count({i, j})) return 1e9;
  int &ans = dp[i][j];
  if (ans != -1) return ans;
  s.insert({i, j});
  ans = 0;
  if (a[i][j] == 'D') {
    if (valid(i - 1, j) && a[i - 1][j] == 'I') ans = max(ans, solve(i - 1, j));
    if (valid(i, j - 1) && a[i][j - 1] == 'I') ans = max(ans, solve(i, j - 1));
    if (valid(i, j + 1) && a[i][j + 1] == 'I') ans = max(ans, solve(i, j + 1));
    if (valid(i + 1, j) && a[i + 1][j] == 'I') ans = max(ans, solve(i + 1, j));
  } else if (a[i][j] == 'I') {
    if (valid(i - 1, j) && a[i - 1][j] == 'M') ans = max(ans, solve(i - 1, j));
    if (valid(i, j - 1) && a[i][j - 1] == 'M') ans = max(ans, solve(i, j - 1));
    if (valid(i, j + 1) && a[i][j + 1] == 'M') ans = max(ans, solve(i, j + 1));
    if (valid(i + 1, j) && a[i + 1][j] == 'M') ans = max(ans, solve(i + 1, j));
  } else if (a[i][j] == 'M') {
    if (valid(i - 1, j) && a[i - 1][j] == 'A') ans = max(ans, solve(i - 1, j));
    if (valid(i, j - 1) && a[i][j - 1] == 'A') ans = max(ans, solve(i, j - 1));
    if (valid(i, j + 1) && a[i][j + 1] == 'A') ans = max(ans, solve(i, j + 1));
    if (valid(i + 1, j) && a[i + 1][j] == 'A') ans = max(ans, solve(i + 1, j));
  } else {
    if (valid(i - 1, j) && a[i - 1][j] == 'D')
      ans = max(ans, 1 + solve(i - 1, j));
    if (valid(i, j - 1) && a[i][j - 1] == 'D')
      ans = max(ans, 1 + solve(i, j - 1));
    if (valid(i, j + 1) && a[i][j + 1] == 'D')
      ans = max(ans, 1 + solve(i, j + 1));
    if (valid(i + 1, j) && a[i + 1][j] == 'D')
      ans = max(ans, 1 + solve(i + 1, j));
    ans = max(ans, 1);
  }
  s.erase({i, j});
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == 'D') mx = max(mx, solve(i, j));
  if (!mx)
    cout << "Poor Dima!" << endl;
  else if (mx >= 1e9)
    cout << "Poor Inna!" << endl;
  else
    cout << mx << endl;
  return 0;
}
