#include <bits/stdc++.h>
using namespace std;
char arr[1001][1001];
long long int used[1001][1001];
long long int ans[1001][1001];
long long int n, m;
long long int inf = 1e18;
long long int p = 1e9 + 7;
long long int phi(long long int n) {
  long long int result = n;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      result -= result / i;
    }
  }
  if (n > 1) result -= result / n;
  return result;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
long long int dfs(long long int x, long long int y) {
  long long int cur = 0;
  long long int temp = 0;
  char s = arr[x][y];
  char f;
  if (used[x][y] == 2) {
    return ans[x][y];
  }
  ans[x][y] = 0;
  used[x][y] = 1;
  if (s == 'D')
    f = 'I';
  else if (s == 'I')
    f = 'M';
  else if (s == 'M')
    f = 'A';
  else
    f = 'D';
  if (x + 1 <= n && arr[x + 1][y] == f) {
    if (used[x + 1][y] != 1) {
      temp = std::max(temp, 1 + dfs(x + 1, y));
    } else if (used[x + 1][y] == 1)
      return inf;
  }
  if (x - 1 >= 0 && arr[x - 1][y] == f) {
    if (used[x - 1][y] != 1) {
      temp = std::max(temp, 1 + dfs(x - 1, y));
    } else if (used[x - 1][y] == 1)
      return inf;
  }
  if (y + 1 <= m && arr[x][y + 1] == f) {
    if (used[x][y + 1] != 1) {
      temp = std::max(temp, 1 + dfs(x, y + 1));
    } else if (used[x][y + 1] == 1)
      return inf;
  }
  if (y - 1 >= 0 && arr[x][y - 1] == f) {
    if (used[x][y - 1] != 1) {
      temp = std::max(temp, 1 + dfs(x, y - 1));
    } else if (used[x][y - 1] == 1)
      return inf;
  }
  if (temp >= inf) temp = inf;
  used[x][y] = 2;
  ans[x][y] = temp;
  return ans[x][y];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int i, j, t, a, b, temp, k, x, y, ctr;
  cin >> n >> m;
  long long int ans = 0;
  memset(used, 0, sizeof(used));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) cin >> arr[i][j];
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (arr[i][j] == 'D' && used[i][j] == 0) {
        ans = std::max(ans, 1 + dfs(i, j));
      }
    }
  }
  if (ans >= inf)
    cout << "Poor Inna!";
  else {
    ans /= 4;
    if (ans == 0)
      cout << "Poor Dima!";
    else
      cout << ans;
  }
  return 0;
}
