#include <bits/stdc++.h>
using namespace std;
template <class T>
T cdiv(T num, T den) {
  return (num / den) + (num % den > 0);
}
template <typename TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
template <class t>
t mag(t a) {
  return a > 0 ? a : -a;
}
std::ifstream term("/dev/tty");
string tempstring;
int tc = 1;
int n, m;
char vec[1010][1010];
int vis[1010][1010], ans[1010][1010];
int mvx[] = {0, 0, -1, 1}, mvy[] = {-1, 1, 0, 0};
string cyc = "DIMA";
bool cycex;
void dfs(int r, int c, int cur) {
  ans[r][c] = 1;
  if (cycex) return;
  vis[r][c] = 1;
  for (int i = 0; i < 4; i++) {
    int tr = r + mvx[i], tc = c + mvy[i];
    if (vec[tr][tc] == cyc[(cur + 1) % 4] and vis[tr][tc] == 1) {
      cycex = 1;
      return;
    }
    if (vec[tr][tc] == cyc[(cur + 1) % 4] and vis[tr][tc] == 2) {
      ans[r][c] = max(ans[r][c], ans[tr][tc] + 1);
    }
    if (vec[tr][tc] == cyc[(cur + 1) % 4] and vis[tr][tc] == 0) {
      dfs(tr, tc, (cur + 1) % 4);
      ans[r][c] = max(ans[r][c], ans[tr][tc] + 1);
    }
  }
  vis[r][c] = 2;
}
int escape() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> vec[i][j];
    }
  }
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (vec[i][j] == 'D' and vis[i][j] == 0) {
        dfs(i, j, 0);
        ret = max(ret, ans[i][j]);
      }
    }
  }
  if (cycex) {
    cout << "Poor Inna!";
    return 0;
  }
  if (ret < 4) {
    cout << "Poor Dima!";
    return 0;
  }
  cout << ret / 4;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  while (tc--) escape();
}
