#include <bits/stdc++.h>
using namespace std;
int n, m;
map<char, char> nextt;
bool is_cycle;
int vis[1000001];
int ans = 0;
map<int, int> ans_at_node;
string str[1001];
bool vis_1[1000001], vis_2[1000001];
int cn(int x, int y) { return x * m + y; }
int dfs_count{};
void dfs_1(int x, int y) {
  int temp_ans = 1;
  ans_at_node[cn(x, y)] = 1;
  if (x > 0) {
    if (str[x - 1][y] == nextt[str[x][y]]) {
      if (vis_1[cn(x - 1, y)]) {
        is_cycle = 1;
        cout << "Poor Inna!\n";
        exit(0);
      } else if (vis_2[cn(x - 1, y)]) {
        ans_at_node[cn(x, y)] =
            max(ans_at_node[cn(x, y)], 1 + ans_at_node[cn(x - 1, y)]);
      } else {
        vis_1[cn(x - 1, y)] = 1;
        vis_2[cn(x - 1, y)] = 1;
        dfs_1(x - 1, y);
        ans_at_node[cn(x, y)] =
            max(ans_at_node[cn(x, y)], 1 + ans_at_node[cn(x - 1, y)]);
        vis_1[cn(x - 1, y)] = 0;
      }
    }
  }
  if (x < n - 1) {
    if (str[x + 1][y] == nextt[str[x][y]]) {
      if (vis_1[cn(x + 1, y)]) {
        is_cycle = 1;
        cout << "Poor Inna!\n";
        exit(0);
      } else if (vis_2[cn(x + 1, y)]) {
        ans_at_node[cn(x, y)] =
            max(ans_at_node[cn(x, y)], 1 + ans_at_node[cn(x + 1, y)]);
      } else {
        vis_1[cn(x + 1, y)] = 1;
        vis_2[cn(x + 1, y)] = 1;
        dfs_1(x + 1, y);
        ans_at_node[cn(x, y)] =
            max(ans_at_node[cn(x, y)], 1 + ans_at_node[cn(x + 1, y)]);
        vis_1[cn(x + 1, y)] = 0;
      }
    }
  }
  if (y > 0) {
    if (str[x][y - 1] == nextt[str[x][y]]) {
      if (vis_1[cn(x, y - 1)]) {
        is_cycle = 1;
        cout << "Poor Inna!\n";
        exit(0);
      } else if (vis_2[cn(x, y - 1)]) {
        ans_at_node[cn(x, y)] =
            max(ans_at_node[cn(x, y)], 1 + ans_at_node[cn(x, y - 1)]);
      } else {
        vis_1[cn(x, y - 1)] = 1;
        vis_2[cn(x, y - 1)] = 1;
        dfs_1(x, y - 1);
        ans_at_node[cn(x, y)] =
            max(ans_at_node[cn(x, y)], 1 + ans_at_node[cn(x, y - 1)]);
        vis_1[cn(x, y - 1)] = 0;
      }
    }
  }
  if (y < m - 1) {
    if (str[x][y + 1] == nextt[str[x][y]]) {
      if (vis_1[cn(x, y + 1)]) {
        is_cycle = 1;
        cout << "Poor Inna!\n";
        exit(0);
      } else if (vis_2[cn(x, y + 1)]) {
        ans_at_node[cn(x, y)] =
            max(ans_at_node[cn(x, y)], 1 + ans_at_node[cn(x, y + 1)]);
      } else {
        vis_1[cn(x, y + 1)] = 1;
        vis_2[cn(x, y + 1)] = 1;
        dfs_1(x, y + 1);
        ans_at_node[cn(x, y)] =
            max(ans_at_node[cn(x, y)], 1 + ans_at_node[cn(x, y + 1)]);
        vis_1[cn(x, y + 1)] = 0;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int i, j, k, l, test_case, r;
  test_case = 1;
  while (test_case--) {
    cin >> ::n >> m;
    for (i = 0; i < n; i++) cin >> str[i];
    vector<pair<int, int> > start;
    nextt['D'] = 'I';
    nextt['I'] = 'M';
    nextt['M'] = 'A';
    nextt['A'] = 'D';
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (str[i][j] == 'D') {
          start.push_back({i, j});
        }
      }
    }
    for (auto it : start) {
      if (vis_2[cn(it.first, it.second)] == 0) {
        vis_2[cn(it.first, it.second)] = 1;
        vis_1[cn(it.first, it.second)] = 1;
        dfs_1(it.first, it.second);
        vis_1[cn(it.first, it.second)] = 0;
      }
      ans = max(ans, ans_at_node[cn(it.first, it.second)]);
    }
    if (ans >= 4)
      cout << ans / 4 << "\n";
    else
      cout << "Poor Dima!\n";
  }
  return 0;
}
