#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 20;
int table[maxn][maxn], ans, dp[maxn * maxn], n, m,
    dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}, cnt, wh[maxn][maxn];
vector<pair<int, int>> graph[maxn][maxn];
pair<int, int> placed[maxn * maxn];
bool vis[maxn][maxn], on[maxn][maxn];
void dfs(int i, int j) {
  vis[i][j] = on[i][j] = 1;
  for (auto x : graph[i][j]) {
    if (on[x.first][x.second]) {
      cout << "Poor Inna!\n";
      exit(0);
    }
    if (!vis[x.first][x.second]) dfs(x.first, x.second);
  }
  wh[i][j] = cnt;
  on[i][j] = 0;
  placed[cnt++] = {i, j};
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s[j] == 'D') table[i][j + 1] = 1;
      if (s[j] == 'I') table[i][j + 1] = 2;
      if (s[j] == 'M') table[i][j + 1] = 3;
      if (s[j] == 'A') table[i][j + 1] = 4;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      for (int k = 0, x, y; k < 4; k++) {
        x = i + dx[k], y = j + dy[k];
        if (table[x][y] == table[i][j] + 1 ||
            (table[i][j] == 4 && table[x][y] == 1))
          graph[i][j].push_back({x, y});
      }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (!vis[i][j]) dfs(i, j);
  for (int i = 0, x, y; i < cnt; i++) {
    x = placed[i].first, y = placed[i].second;
    for (auto j : graph[x][y]) dp[i] = max(dp[i], dp[wh[j.first][j.second]]);
    if (table[x][y] == 4) dp[i]++;
    if (table[x][y] == 1) ans = max(ans, dp[i]);
  }
  if (ans == 0)
    cout << "Poor Dima!\n";
  else
    cout << ans << endl;
}
