#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long dx[] = {-1, 0, 1, 0};
long long dy[] = {0, 1, 0, -1};
long long fast_exp(long long base, long long exp) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = (res * base) % MOD;
    base = (base * base) % MOD;
    exp /= 2;
  }
  return res % MOD;
}
vector<string> A;
string s = "DIMA";
vector<vector<long long>> dp;
long long n, m;
long long dfs(long long x, long long y, long long ind) {
  if (dp[x][y] != -1) return dp[x][y];
  dp[x][y] = 1e18;
  ind = (ind + 1) % 4;
  long long tmp = 1;
  for (long long i = 0; i < 4; i++) {
    long long p1 = dx[i] + x;
    long long p2 = dy[i] + y;
    if (p1 >= 0 and p1 < n and p2 >= 0 and p2 < m and A[p1][p2] == s[ind]) {
      tmp = max(tmp, 1 + dfs(p1, p2, ind));
    }
  }
  return dp[x][y] = min(dp[x][y], tmp);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  A.clear();
  A.resize(n);
  for (long long i = 0; i < n; i++) cin >> A[i];
  dp.clear();
  dp.resize(n + 1, vector<long long>(m + 1, -1));
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (A[i][j] == 'D') {
        ans = max(ans, dfs(i, j, 0));
      }
    }
  }
  if (ans == 1e18)
    cout << "Poor Inna!" << endl;
  else {
    ans = ans / 4;
    if (ans == 0)
      cout << "Poor Dima!\n";
    else
      cout << ans << endl;
  }
  return 0;
}
