#include <bits/stdc++.h>
using namespace std;
long long m, ANS = -1, n, CYCLE = 1;
bool FLAG = 0;
long long visited[1010][1010];
long long dp[1010][1010];
string str[1010];
string str2 = "DIMA";
bool chck(long long x, long long y) {
  if (x < 0 || y < 0 || x >= n || y >= m) return 0;
  return 1;
}
long long dfs(long long x, long long y, long long op) {
  long long op2 = (op + 1) % 4;
  long long ans = 0;
  if (dp[x][y] != -1) return dp[x][y];
  if (visited[x][y] == CYCLE) {
    FLAG = 1;
    return 0;
  }
  visited[x][y] = CYCLE;
  long long i, j;
  for (i = -1; i <= 1; i++) {
    for (j = -1; j <= 1; j++) {
      if (abs(i) + abs(j) != 1) continue;
      if (chck(x + i, y + j) && str[x + i][y + j] == str2[op2])
        ans = max(ans, 1 + dfs(x + i, y + j, op2));
    }
  }
  dp[x][y] = ans;
  return ans;
}
int main() {
  long long t, i, j, k, l;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> str[i];
  long long res = 0;
  memset(dp, -1, sizeof(dp));
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      if (!visited[i][j] && str[i][j] == 'D') {
        ANS = -1;
        res = max(res, dfs(i, j, 0));
        CYCLE++;
        if (FLAG) {
          cout << "Poor Inna!\n";
          return 0;
        }
      }
    }
  res++;
  res /= 4;
  if (res == 0)
    cout << "Poor Dima!\n";
  else
    cout << res << '\n';
  return 0;
}
