#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
vector<pair<long long, long long>> d;
long long n, m;
char grid[1002][1002];
bool visited[1002][1002];
vector<long long> ans;
vector<char> v{'D', 'I', 'M', 'A'};
vector<long long> idi{-1, 1, 0, 0};
vector<long long> idj{0, 0, -1, 1};
bool flag = false;
long long dp[1002][1002][5];
long long dfs(pair<long long, long long> id, long long a_id,
              pair<long long, long long> prev) {
  long long i = id.first;
  long long j = id.second;
  if (i < 1 || j < 1 || i > n || j > m || grid[i][j] != v[a_id]) return 0;
  if (visited[i][j]) {
    flag = true;
    return 0;
  }
  if (dp[i][j][a_id] != -1) return dp[i][j][a_id];
  visited[i][j] = true;
  long long cnt = 0;
  for (long long l = 0; l < 4; l++) {
    long long next_x = i + idi[l];
    long long next_y = j + idj[l];
    long long prev_i = prev.first;
    long long prev_j = prev.second;
    if ((prev_i == next_x) && (prev_j == next_y)) continue;
    cnt = max(cnt, dfs({next_x, next_y}, (a_id + 1) % 4, {i, j}) + 1);
  }
  visited[i][j] = false;
  return dp[i][j][a_id] = cnt;
}
void mysol() {
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  memset(visited, false, sizeof(visited));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == 'D') d.push_back({i, j});
    }
  }
  if (d.size() == 0) {
    cout << "Poor Dima!";
    return;
  }
  for (auto d_id : d) {
    ans.push_back(dfs(d_id, 0, {1, 1}) / 4);
  }
  if (flag) {
    cout << "Poor Inna!";
    return;
  }
  long long an = *max_element(ans.begin(), ans.end());
  if (an == 0)
    cout << "Poor Dima!" << '\n';
  else
    cout << an << '\n';
}
int32_t main() {
  fast();
  { mysol(); }
  return 0;
}
