#include <bits/stdc++.h>
using namespace std;
int n, m, vis[1010][1010], dp[1010][1010], ans;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
char grid[1010][1010], str[] = "DIMA";
int dfs(int x, int y, int k) {
  if (x < 0 || x >= n || y < 0 || y >= m || grid[x][y] != str[k]) {
    return 0;
  }
  if (vis[x][y] == 2) {
    return dp[x][y];
  }
  if (vis[x][y] == 1) {
    return 1e9;
  }
  vis[x][y] = 1;
  int &ret = dp[x][y];
  for (int i = 0; i < 4; i++) {
    ret = max(ret, dfs(x + dx[i], y + dy[i], (k + 1) % 4));
  }
  vis[x][y] = 2;
  return ++ret;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> grid[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!vis[i][j]) {
        ans = max(ans, dfs(i, j, 0));
      }
    }
  }
  if (ans >= 1e9) {
    cout << "Poor Inna!\n";
  } else if (ans / 4 == 0) {
    cout << "Poor Dima!\n";
  } else {
    cout << ans / 4 << endl;
  }
  return 0;
}
