#include <bits/stdc++.h>
using namespace std;
vector<string> s;
vector<vector<int> > mem;
map<char, char> mp;
int n, m, vis[1003][1003], ans;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
bool cyc(int a, int b) {
  if (s[a][b] == 'D' and vis[a][b] == 1) {
    return 1;
  }
  bool ret = 0;
  vis[a][b] = 1;
  for (int i = 0; i < 4; i++) {
    int x = a + dx[i], y = b + dy[i];
    if (x >= 0 and x < n and y >= 0 and y < m and mp[s[a][b]] == s[x][y] and
        vis[x][y] != 2) {
      ret |= cyc(x, y);
    }
  }
  vis[a][b] = 2;
  return ret;
}
int path(int a, int b) {
  if (vis[a][b] != -1) {
    return vis[a][b];
  }
  int ret = 1;
  for (int i = 0; i < 4; i++) {
    int x = a + dx[i], y = b + dy[i];
    if (x >= 0 and x < n and y >= 0 and y < m and mp[s[a][b]] == s[x][y]) {
      int tmp = vis[x][y];
      if (tmp == -1)
        ret = max(ret, path(x, y) + 1);
      else
        ret = max(ret, tmp + 1);
    }
  }
  return vis[a][b] = ret;
}
int main() {
  mp['D'] = 'I';
  mp['I'] = 'M';
  mp['M'] = 'A';
  mp['A'] = 'D';
  cin >> n >> m;
  s.resize(n);
  mem.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    mem[i].resize(m);
    for (int j = 0; j < m; j++) {
      mem[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'D' and !mem[i][j]) {
        if (cyc(i, j)) {
          puts("Poor Inna!");
          return 0;
        }
      }
    }
  }
  memset(vis, -1, sizeof vis);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'D' and vis[i][j] == -1) {
        ans = max(ans, path(i, j) / 4);
      }
    }
  }
  if (ans == 0) {
    puts("Poor Dima!");
  } else {
    cout << ans << endl;
  }
  return 0;
}
