#include <bits/stdc++.h>
using namespace std;
const int N = 1111, inf = 1e9, mod = 1e9 + 7;
const long long linf = 1e18;
int ans[N][N], color[N][N], n, m, k, dir[4][2], res;
char ch[N][N], c[N];
vector<pair<int, int> > g[N][N];
bool check(int x, int y) { return x >= 1 && y >= 1 && x <= n && y <= m; }
void dfs(int x, int y) {
  color[x][y] = k;
  ans[x][y] = 0;
  for (int i = 0; i < g[x][y].size(); i++) {
    pair<int, int> to = g[x][y][i];
    if (color[to.first][to.second] == color[x][y]) {
      cout << "Poor Inna!";
      exit(0);
    }
    if (!color[to.first][to.second]) dfs(to.first, to.second);
    ans[x][y] = max(ans[x][y], ans[to.first][to.second]);
  }
  if (ch[x][y] == 'A') ans[x][y]++;
  color[x][y] = 1000000;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  dir[0][0] = dir[1][1] = 1;
  dir[2][0] = dir[3][1] = -1;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> ch[i][j];
  c['D' - 'A'] = 'I';
  c['I' - 'A'] = 'M';
  c['M' - 'A'] = 'A';
  c['A' - 'A'] = 'D';
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      for (int q = 0; q < 4; q++) {
        int x = i + dir[q][0];
        int y = j + dir[q][1];
        if (ch[x][y] == c[ch[i][j] - 'A']) g[i][j].push_back(make_pair(x, y));
      }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (ch[i][j] == 'D' && !color[i][j]) {
        k++;
        dfs(i, j);
        res = max(res, ans[i][j]);
      }
    }
  if (res)
    cout << res;
  else
    cout << "Poor Dima!";
  return 0;
}
