#include <bits/stdc++.h>
using namespace std;
int val[1001][1001], vis[1001][1001], n, m;
char s[1001][1001];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
char ch1[] = {'D', 'I', 'M', 'A'};
char ch2[] = {'I', 'M', 'A', 'D'};
bool check(int x, int y) {
  if (x < 0 || y < 0 || y >= m || x >= n) return 0;
  return 1;
}
int flag = 0;
int dfs(int x, int y) {
  int ans = 0, m1 = 0;
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    if (check(x + dx[i], y + dy[i])) {
      int f = 0;
      ans = 0;
      for (int j = 0; j < 4; j++)
        if (s[x][y] == ch1[j] && s[x + dx[i]][y + dy[i]] == ch2[j]) {
          f = 1;
          break;
        }
      if (f == 0) continue;
      if (vis[x + dx[i]][y + dy[i]] == 1 && val[x + dx[i]][y + dy[i]] == -1) {
        flag = -1;
      } else if (vis[x + dx[i]][y + dy[i]] == 1 &&
                 val[x + dx[i]][y + dy[i]] != -1)
        ans += val[x + dx[i]][y + dy[i]];
      else if (vis[x + dx[i]][y + dy[i]] == 0) {
        ans += dfs(x + dx[i], y + dy[i]);
      }
    }
    m1 = max(m1, ans);
  }
  return val[x][y] = 1 + m1;
}
int main() {
  int i, j, ans = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> s[i];
  memset(vis, 0, sizeof(vis));
  memset(val, -1, sizeof(val));
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      if (s[i][j] == 'D') {
        if (vis[i][j] == 0) ans = max(ans, dfs(i, j));
      }
    }
  if (ans / 4 == 0)
    cout << "Poor Dima!" << endl;
  else if (flag == -1)
    cout << "Poor Inna!" << endl;
  else
    cout << ans / 4 << endl;
  return 0;
}
