#include <bits/stdc++.h>
const static long long INF = 0x3f3f3f3f3f3f3f3f;
static inline void setio(void);
const long long MAX_N = 1e3 + 7;
std::vector<std::pair<long long, long long> > gr[MAX_N][MAX_N];
long long in[MAX_N][MAX_N], bef[MAX_N][MAX_N];
const std::string dima = "DIMA";
std::string grid[MAX_N];
int main(void) {
  setio();
  long long n, m;
  std::cin >> n >> m;
  for (long long i = 0; i < n; ++i) std::cin >> grid[i];
  for (const auto& letter : dima)
    for (long long i = 0; i < n; ++i) {
      for (long long j = 0; j < m; ++j) {
        if (grid[i][j] != letter) continue;
        if (grid[i][j] != 'D' && in[i][j] == 0) continue;
        long long idx = dima.find(std::string(1, grid[i][j]));
        idx = (idx + 1) % 4;
        const char& next = dima[idx];
        for (long long x = -1; x <= 1; ++x)
          for (long long y = -1; y <= 1; ++y)
            if ((x == 0 || y == 0) && i + x >= 0 && i + x < n && j + y >= 0 &&
                j + y < m && grid[i + x][j + y] == next) {
              gr[i][j].push_back({i + x, j + y});
              in[i + x][j + y]++;
            }
      }
    }
  std::queue<std::pair<long long, long long> > order;
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < m; ++j)
      if (grid[i][j] == 'D' && in[i][j] == 0) {
        order.push(std::pair<long long, long long>{i, j});
        bef[i][j] = 1;
      }
  while (order.size()) {
    std::pair<long long, long long> now = order.front();
    order.pop();
    const long long i = now.first, j = now.second;
    for (const auto& nei : gr[i][j]) {
      const long long &x = nei.first, y = nei.second;
      bef[x][y] = std::max(bef[x][y], 1 + bef[i][j]);
      if (--in[x][y] == 0) order.push(nei);
    }
  }
  long long max = 0;
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < m; ++j) {
      max = std::max(max, bef[i][j]);
      if (grid[i][j] == 'D' && in[i][j]) {
        std::cout << "Poor Inna!\n";
        return 0;
      }
    }
  if (max < 4)
    std::cout << "Poor Dima!\n";
  else
    std::cout << max / 4 << "\n";
  return 0;
}
static inline void setio(void) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(10);
  std::cout << std::fixed;
}
