#include <bits/stdc++.h>
using namespace std;
const int N = 2005, INF = 2e7 + 5;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool stk[N * N];
int dp[N * N];
string a[N];
char X[N * N];
vector<int> adj[N * N];
int n, m, curID;
bool f = 0;
bool valid(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }
void Search(int x, int y, int c, string s) {
  if (c == (int)s.size()) {
    adj[curID].push_back(x * m + y);
    if ((int)s.size() == 4 && (X[curID] != 'D' || X[x * m + y] != 'A'))
      assert(0);
    else if ((int)s.size() == 1 && (X[curID] != 'A' || X[x * m + y] != 'D'))
      assert(0);
    return;
  }
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (valid(nx, ny) && a[nx][ny] == s[c]) Search(nx, ny, c + 1, s);
  }
}
int solve(int u) {
  int &ret = dp[u];
  if (~ret) return ret;
  ret = 0;
  stk[u] = 1;
  for (auto v : adj[u]) {
    if (stk[v]) f = 1;
    ret = max(ret, solve(v) + (X[u] == 'D'));
  }
  stk[u] = 0;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) X[i * m + j] = a[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 'D') {
        curID = i * m + j;
        Search(i, j, 1, "DIMA");
      }
      if (a[i][j] == 'A') {
        curID = i * m + j;
        Search(i, j, 0, "D");
      }
    }
  memset(dp, -1, sizeof dp);
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == 'D') ans = max(ans, solve(i * m + j));
  if (ans == 0)
    cout << "Poor Dima!" << endl;
  else if (f)
    cout << "Poor Inna!" << endl;
  else
    cout << ans << endl;
  return 0;
}
