#include <bits/stdc++.h>
using namespace std;
class loop_detected_exception : public exception {};
const int MAXN = 1010;
char ma[MAXN][MAXN];
int opt[MAXN][MAXN];
int mark[MAXN][MAXN];
int n, m;
int ans = 0;
int step = 0;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int dfs(int x, int y, int startx, int starty) throw(loop_detected_exception) {
  if (mark[x][y] == step) throw loop_detected_exception();
  mark[x][y] = step;
  if (opt[x][y] != -1) {
    mark[x][y] = 0;
    return opt[x][y];
  }
  if (ma[x][y] == 'A') {
    int ret = 1;
    for (int k = 0; k < 4; ++k) {
      int nx = x + dx[k];
      int ny = y + dy[k];
      if (nx >= 0 && nx < n && ny >= 0 && ny < m && ma[nx][ny] == 'D')
        dfs(nx, ny, nx, ny), ret = max(ret, opt[nx][ny] + 1);
    }
    mark[x][y] = 0;
    return opt[startx][starty] = max(opt[startx][starty], ret);
  }
  char next = ma[x][y];
  switch (ma[x][y]) {
    case 'D':
      next = 'I';
      break;
    case 'I':
      next = 'M';
      break;
    case 'M':
      next = 'A';
      break;
  }
  int ret = 0;
  for (int k = 0; k < 4; ++k) {
    int nx = x + dx[k];
    int ny = y + dy[k];
    if (nx >= 0 && nx < n && ny >= 0 && ny < m && ma[nx][ny] == next)
      ret = max(ret, dfs(nx, ny, startx, starty));
  }
  mark[x][y] = 0;
  return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> ma[i];
  try {
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) opt[i][j] = -1;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j)
        if (ma[i][j] == 'D') {
          ++step;
          dfs(i, j, i, j);
        }
    int ans = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) ans = max(ans, opt[i][j]);
    if (!ans)
      cout << "Poor Dima!" << endl;
    else
      cout << ans << endl;
  } catch (loop_detected_exception &e) {
    cout << "Poor Inna!" << endl;
  }
  return 0;
}
