#include <bits/stdc++.h>
using namespace std;
int dirx[] = {1, 0, -1, 0};
int diry[] = {0, -1, 0, 1};
const string DIMA = "DIMA";
vector<string> board;
int color[1024][1024];
int dp[1024][1024];
int dfs(int x, int y, int index) {
  char target = DIMA[index];
  if (board[x][y] == target) {
    int& ret = dp[x][y];
    if (ret != -1) return ret;
    color[x][y] = 1;
    ret = 0;
    for (int d = 0; d < 4; d++) {
      int nx = x + dirx[d];
      int ny = y + diry[d];
      if (nx >= 0 && nx < board.size() && ny >= 0 && ny < board[0].size()) {
        if (board[nx][ny] == DIMA[(index + 1) % DIMA.size()]) {
          if (color[nx][ny] == 1) {
            ret = -1;
            break;
          } else {
            int nret = dfs(nx, ny, (index + 1) % DIMA.size());
            if (nret == -1) {
              ret = -1;
              break;
            } else {
              ret = max(ret, nret);
            }
          }
        }
      }
    }
    color[x][y] = 2;
    if (index == DIMA.size() - 1 && ret != -1) ret++;
    return ret;
  } else {
    return 0;
  }
}
int main() {
  int n, m;
  while (cin >> n >> m) {
    board.clear();
    for (int i = 0; i < n; i++) {
      string tmp;
      cin >> tmp;
      board.push_back(tmp);
    }
    memset(color, 0, sizeof(color));
    memset(dp, -1, sizeof(dp));
    int ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int nret = dfs(i, j, 0);
        if (nret == -1) {
          ret = -1;
          goto EXIT;
        } else {
          ret = max(ret, nret);
        }
      }
    }
  EXIT:
    if (ret == -1) {
      cout << "Poor Inna!" << endl;
    } else if (ret == 0) {
      cout << "Poor Dima!" << endl;
    } else {
      cout << ret << endl;
    }
  }
}
