#include <bits/stdc++.h>
using namespace std;
int n, j, mx, last, ch;
char a[100010];
bool vis[100010];
int check(int x) {
  last = -1;
  for (int i = 0; i < n; ++i) {
    if (a[i] == '*' && last == -1) last = i;
    if (a[i] == 'P') {
      if (last != -1) {
        ch = i - last;
        if (ch > x) return 0;
        last = -1;
        mx = i + max(x - ch * 2, (x - ch) / 2);
        for (; i < min(n, mx); ++i)
          if (a[i + 1] == 'P') break;
      } else {
        mx = i + x;
        for (; i < min(n, mx); ++i)
          if (a[i + 1] == 'P') break;
      }
    }
  }
  if (last != -1) return 0;
  return 1;
}
int main() {
  scanf("%d", &n);
  scanf("%s", a);
  int l = 1, r = 2 * n, mid;
  while (l <= r) {
    mid = l + r >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << r + 1;
  return 0;
}
