#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    long long t = bigmod(p, e / 2, M);
    return (T)((t * t) % M);
  }
  return (T)(((long long)bigmod(p, e - 1, M) * (long long)(p)) % M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
int flag = 0;
long long ar[1001][1001], n, m;
char pp[1001][1001];
string s1 = "DIMA";
string s2 = "IMAD";
int nxt[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
long long val[1001][1001], cnt = 0;
int dfs(int x, int y) {
  if (ar[x][y] == 1) {
    flag = 1;
    return 0;
  }
  if (ar[x][y] != 0) return val[x][y];
  int res = 0;
  ar[x][y] = 1;
  for (int i = (0); i < (4); ++i) {
    if (s1[i] == pp[x][y]) {
      if (s1[i] == 'A') res = 1;
      for (int j = (0); j < (4); ++j) {
        int a = x + nxt[j][0];
        int b = y + nxt[j][1];
        if (a >= 0 && a < n && b >= 0 && b < m && pp[a][b] == s2[i]) {
          int c = dfs(a, b);
          if (pp[a][b] == 'D')
            res = max(res, 1 + c);
          else
            res = max(res, c);
        }
      }
    }
  }
  ar[x][y] = 2;
  return val[x][y] = res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long a = 1, b, c, d, e, f, g, h = 0, x, y, z;
  cin >> a >> b;
  n = a;
  m = b;
  for (int i = (0); i < (a); ++i) cin >> pp[i];
  for (int i = (0); i < (a); ++i) {
    for (int j = (0); j < (b); ++j) {
      if (ar[i][j] == 0 && pp[i][j] == 'D') h = max((int)h, dfs(i, j));
    }
  }
  if (flag == 1)
    cout << "Poor Inna!";
  else if (h == 0)
    cout << "Poor Dima!";
  else
    cout << h << endl;
}
