#include <bits/stdc++.h>
using namespace std;
const int maxn = 1009;
string arr[maxn];
int n, m;
int dp[maxn][maxn] = {0};
const int dir[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1};
const char dima[4] = {'D', 'I', 'M', 'A'};
bool inf = false;
bool vis[maxn][maxn] = {false};
bool Check(int x, int y, int dim) {
  if (x < 0 || y < 0 || x >= n || y >= m || arr[x][y] != dima[(dim + 1) % 4]) {
    return false;
  }
  return true;
}
int Dfs(int x, int y, int dim) {
  if (dp[x][y]) {
    return dp[x][y];
  }
  if (vis[x][y]) {
    inf = true;
    return 0;
  }
  if (inf) {
    return 0;
  }
  vis[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int xt = x + dir[i][0], yt = y + dir[i][1];
    if (Check(xt, yt, dim)) {
      dp[x][y] = max(dp[x][y], Dfs(xt, yt, (dim + 1) % 4));
    }
  }
  vis[x][y] = false;
  if (dim == 3) {
    dp[x][y]++;
  }
  return dp[x][y];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      arr[i] = s;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == 'D') {
        Dfs(i, j, 0);
        ans = max(ans, dp[i][j]);
      }
    }
  }
  if (ans == 0) {
    cout << "Poor Dima!" << endl;
  } else if (inf) {
    cout << "Poor Inna!" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
