#include <bits/stdc++.h>
using namespace std;
const long long N = 1005;
char a[N][N];
long long n, m;
long long cache[N][N][4];
bool vis[N][N][4];
long long dx[] = {+1, -1, 0, 0};
long long dy[] = {0, 0, -1, +1};
char b[4] = {'D', 'I', 'M', 'A'};
long long dp(long long i, long long j, long long prev) {
  if (i < 1 || i > n || j < 1 || j > m) return 0;
  if (vis[i][j][prev]) return 1e9;
  char shouldbe = b[(prev + 1) % 4];
  if (a[i][j] != shouldbe) return 0;
  long long &res = cache[i][j][prev];
  if (res != -1) return res;
  vis[i][j][prev] = 1;
  long long val = (prev == 2) ? 1 : 0;
  res = 0;
  for (long long k = 0; k < 4; k++)
    res = max(res, val + dp(i + dx[k], j + dy[k], (prev + 1) % 4));
  vis[i][j][prev] = 0;
  return res;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) cin >> a[i][j];
  memset(cache, -1, sizeof(cache));
  long long ans = 0;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) ans = max(ans, dp(i, j, 3));
  if (!ans)
    cout << "Poor Dima!";
  else if (ans > n * m)
    cout << "Poor Inna!";
  else
    cout << ans;
  return 0;
}
