#include <bits/stdc++.h>
using namespace std;
template <class T>
T Max(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
T Min(T &a, T b) {
  if (a > b) a = b;
}
struct info {
  int r, c;
} orig[1001][1001];
int a_x[] = {1, 0, 0, -1};
int a_y[] = {0, -1, 1, 0};
char grid[1005][1005];
int visit[1005][1005];
int dp[1005][1005];
int n, m;
int res = 0;
int inf = 0;
int check = 0;
char ch[10];
int first = 0;
int dfs(int x, int y, int or1, int or2, int pos) {
  if (inf) return 0;
  if (visit[x][y] == 1) {
    inf = 1;
    return 0;
  }
  if (visit[x][y] == 2) return dp[x][y];
  int i, j;
  int out = 0;
  if (pos % 4 == 3) out = 1;
  visit[x][y] = 1;
  int maggoma = 0;
  for (i = 0; i <= 3; i++) {
    int e = x + a_x[i];
    int f = y + a_y[i];
    int q = out;
    if (e >= 1 && e <= n && f >= 1 && f <= m &&
        grid[e][f] == ch[(pos + 1) % 4]) {
      q += dfs(e, f, or1, or2, (pos + 1) % 4);
    }
    maggoma = max(maggoma, q);
  }
  visit[x][y] = 2;
  return dp[x][y] = maggoma;
}
int main() {
  int i, j;
  cin >> n >> m;
  getchar();
  ch[0] = 'D', ch[1] = 'I', ch[2] = 'M', ch[3] = 'A';
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) scanf("%c", &grid[i][j]);
    getchar();
  }
  int z = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      inf = 0;
      if (grid[i][j] == 'D' && !visit[i][j]) {
        int t = dfs(i, j, i, j, 0);
        res = max(res, t);
        if (inf) {
          cout << "Poor Inna!";
          return 0;
        }
      }
    }
  }
  if (res == 0)
    cout << "Poor Dima!";
  else
    cout << res;
  cout << endl;
  return 0;
}

### Prompt

Please create a solution in Cpp to the following problem:

Inna and Dima bought a table of size n × m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A".

Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows:

  1. initially, Inna chooses some cell of the table where letter "D" is written; 
  2. then Inna can move to some side-adjacent table cell that contains letter "I"; then from this cell she can go to one of the side-adjacent table cells that contains the written letter "M"; then she can go to a side-adjacent cell that contains letter "A". Then Inna assumes that she has gone through her sweetheart's name; 
  3. Inna's next move can be going to one of the side-adjacent table cells that contains letter "D" and then walk on through name DIMA in the similar manner. Inna never skips a letter. So, from the letter "D" she always goes to the letter "I", from the letter "I" she always goes the to letter "M", from the letter "M" she always goes to the letter "A", and from the letter "A" she always goes to the letter "D". 



Depending on the choice of the initial table cell, Inna can go through name DIMA either an infinite number of times or some positive finite number of times or she can't go through his name once. Help Inna find out what maximum number of times she can go through name DIMA.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 103). 

Then follow n lines that describe Inna and Dima's table. Each line contains m characters. Each character is one of the following four characters: "D", "I", "M", "A". 

Note that it is not guaranteed that the table contains at least one letter "D".

Output

If Inna cannot go through name DIMA once, print on a single line "Poor Dima!" without the quotes. If there is the infinite number of names DIMA Inna can go through, print "Poor Inna!" without the quotes. Otherwise print a single integer — the maximum number of times Inna can go through name DIMA.

Examples

Input

1 2
DI


Output

Poor Dima!


Input

2 2
MA
ID


Output

Poor Inna!


Input

5 5
DIMAD
DIMAI
DIMAM
DDMAA
AAMID


Output

4

Note

Notes to the samples:

In the first test sample, Inna cannot go through name DIMA a single time.

In the second test sample, Inna can go through the infinite number of words DIMA. For that, she should move in the clockwise direction starting from the lower right corner.

In the third test sample the best strategy is to start from the cell in the upper left corner of the table. Starting from this cell, Inna can go through name DIMA four times. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
T Max(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
T Min(T &a, T b) {
  if (a > b) a = b;
}
struct info {
  int r, c;
} orig[1001][1001];
int a_x[] = {1, 0, 0, -1};
int a_y[] = {0, -1, 1, 0};
char grid[1005][1005];
int visit[1005][1005];
int dp[1005][1005];
int n, m;
int res = 0;
int inf = 0;
int check = 0;
char ch[10];
int first = 0;
int dfs(int x, int y, int or1, int or2, int pos) {
  if (inf) return 0;
  if (visit[x][y] == 1) {
    inf = 1;
    return 0;
  }
  if (visit[x][y] == 2) return dp[x][y];
  int i, j;
  int out = 0;
  if (pos % 4 == 3) out = 1;
  visit[x][y] = 1;
  int maggoma = 0;
  for (i = 0; i <= 3; i++) {
    int e = x + a_x[i];
    int f = y + a_y[i];
    int q = out;
    if (e >= 1 && e <= n && f >= 1 && f <= m &&
        grid[e][f] == ch[(pos + 1) % 4]) {
      q += dfs(e, f, or1, or2, (pos + 1) % 4);
    }
    maggoma = max(maggoma, q);
  }
  visit[x][y] = 2;
  return dp[x][y] = maggoma;
}
int main() {
  int i, j;
  cin >> n >> m;
  getchar();
  ch[0] = 'D', ch[1] = 'I', ch[2] = 'M', ch[3] = 'A';
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) scanf("%c", &grid[i][j]);
    getchar();
  }
  int z = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      inf = 0;
      if (grid[i][j] == 'D' && !visit[i][j]) {
        int t = dfs(i, j, i, j, 0);
        res = max(res, t);
        if (inf) {
          cout << "Poor Inna!";
          return 0;
        }
      }
    }
  }
  if (res == 0)
    cout << "Poor Dima!";
  else
    cout << res;
  cout << endl;
  return 0;
}

```