#include <bits/stdc++.h>
using namespace std;
const long long logN = 20;
const long long N = 100005;
const long long M = 1000000007;
const long long INF = 1e12;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
string s[1005], a;
long long dp[1005][1005];
bool vis[1005][1005], done[1005][1005];
long long n, m;
long long b, ans1;
bool check(long long x, long long y) {
  if (x >= 0 and y >= 0 and x < n and y < m) return 1;
  return 0;
}
long long dfs(long long x, long long y, long long f) {
  if (vis[x][y]) {
    b = -1;
    return 0;
  }
  long long ans = 0;
  if (dp[x][y] != -1) {
    return dp[x][y];
  }
  vis[x][y] = 1;
  for (long long i = 0; i < 4; i++) {
    if (!check(x + dx[i], y + dy[i])) continue;
    if (s[x + dx[i]][y + dy[i]] == a[f]) {
      if (f == 3) {
        ans = max(ans, dfs(x + dx[i], y + dy[i], 0) + 1);
      } else {
        ans = max(ans, dfs(x + dx[i], y + dy[i], f + 1) + 1);
      }
    }
  }
  vis[x][y] = 0;
  done[x][y] = 1;
  dp[x][y] = ans;
  ans1 = max(ans1, dp[x][y]);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  a = "DIMA";
  for (long long i = 0; i < n; i++) cin >> s[i];
  memset(dp, -1, sizeof(dp));
  long long cnt = 0;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      if (!done[i][j] and s[i][j] == 'D') dfs(i, j, 1);
      if (b == -1) {
        cout << "Poor Inna!"
             << "\n";
        return 0;
      }
    }
  if ((ans1 + 1) / 4 == 0) {
    cout << "Poor Dima!"
         << "\n";
  } else {
    cout << (ans1 + 1) / 4 << "\n";
  }
  return 0;
}
