#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265359;
const double EPS = 1e-9;
const long long INF = ((long long)1 << 60);
int dir[4][4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
long long memo[1100][1100];
int in_stack[1100][1100];
int visited[1100][1100];
map<char, char> next_let;
long long dfs(vector<string> &grid, int cy, int cx) {
  if (grid[cy][cx] == '#') return 0;
  if (in_stack[cy][cx]) return INF;
  if (visited[cy][cx]) return memo[cy][cx];
  visited[cy][cx] = 1;
  in_stack[cy][cx] = 1;
  long long res = 1;
  for (int i = 0; i < 4; i++) {
    int ny = dir[i][0] + cy;
    int nx = dir[i][1] + cx;
    if (grid[ny][nx] == next_let[grid[cy][cx]]) {
      res = max(res, 1 + dfs(grid, ny, nx));
    }
  }
  in_stack[cy][cx] = 0;
  return memo[cy][cx] = res;
}
int main() {
  std::ios::sync_with_stdio(false);
  next_let['D'] = 'I';
  next_let['I'] = 'M';
  next_let['M'] = 'A';
  next_let['A'] = 'D';
  int n, m;
  cin >> n >> m;
  vector<string> grid;
  string tmp;
  grid.push_back(string(m + 2, '#'));
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    grid.push_back("#" + tmp + "#");
  }
  grid.push_back(string(m + 2, '#'));
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; j++) {
      if (!visited[i][j] && grid[i][j] == 'D') {
        res = max(res, dfs(grid, i, j));
      }
    }
  }
  res /= 4;
  if (res >= n * m) {
    cout << "Poor Inna!\n";
  } else if (res == 0) {
    cout << "Poor Dima!\n";
  } else {
    cout << res << endl;
  }
  return 0;
}
