#include <bits/stdc++.h>
using namespace std;
const int sz = 1005;
string a[sz], s = "DIMA";
bool dad[sz][sz], cy = 0;
int n, m, mem[sz][sz], xd[] = {-1, 1, 0, 0}, yd[] = {0, 0, 1, -1};
bool valid(int x, int y, int p) {
  if (x >= 0 && x < n && y >= 0 && y < m && a[x][y] == s[p]) return 1;
  return 0;
}
int solve(int i, int j, int p) {
  if (dad[i][j]) {
    cy = 1;
    return 0;
  }
  int &ret = mem[i][j];
  if (ret != -1) return ret;
  ret = 0;
  dad[i][j] = 1;
  int add = (p == 3 ? 1 : 0);
  for (int k = 0; k < 4; k++) {
    int nx = i + xd[k], ny = j + yd[k];
    if (valid(nx, ny, p)) ret = max(ret, solve(nx, ny, (p + 1) % 4) + add);
  }
  dad[i][j] = 0;
  return ret;
}
int main() {
  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++) mem[i][j] = -1;
  int maxi = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == 'D') maxi = max(maxi, solve(i, j, 1));
  if (cy)
    cout << "Poor Inna!" << endl;
  else if (!maxi)
    cout << "Poor Dima!" << endl;
  else
    cout << maxi << endl;
  return 0;
}
