#include <bits/stdc++.h>
using namespace std;
const int MX = 1007;
const int INF = 1e8 + 7;
int n, m;
char grid[MX][MX];
long long dp[MX][MX];
int Vis[MX][MX];
char dir[] = {'D', 'I', 'M', 'A'};
long long solve(int i, int j, int pos) {
  if (i < 0 || j < 0 || i == n || j == m) return 0;
  if (grid[i][j] != dir[pos]) return 0;
  if (Vis[i][j] == true) return INF;
  if (dp[i][j] != -1) return dp[i][j];
  Vis[i][j] = true;
  long long ret = 0;
  ret = max(ret, solve(i, j + 1, (pos + 1) % 4));
  ret = max(ret, solve(i, j - 1, (pos + 1) % 4));
  ret = max(ret, solve(i + 1, j, (pos + 1) % 4));
  ret = max(ret, solve(i - 1, j, (pos + 1) % 4));
  dp[i][j] = ret;
  if (pos == 3) dp[i][j]++;
  Vis[i][j] = false;
  return dp[i][j];
}
int main() {
  cin >> n >> m;
  vector<pair<int, int> > Pos;
  for (__typeof((n)-1) i = (0); i <= (n)-1; ++i) {
    for (__typeof((m)-1) j = (0); j <= (m)-1; ++j) {
      cin >> grid[i][j];
      if (grid[i][j] == 'D') Pos.push_back(make_pair(i, j));
    }
  }
  long long ret = 0;
  memset(dp, -1, sizeof dp);
  int sz = Pos.size();
  for (int i = 0; i < sz && ret <= INF; i++) {
    ret = max(ret, solve(Pos[i].first, Pos[i].second, 0));
  }
  if (ret == 0)
    cout << "Poor Dima!" << endl;
  else if (ret >= INF)
    cout << "Poor Inna!" << endl;
  else
    cout << ret << endl;
}
