#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int read() {
  int x = 0, f = 1;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') && (f = -f);
  for (x = ch ^ 48; isdigit(ch = getchar());
       x = (x << 3) + (x << 1) + (ch ^ 48))
    ;
  return x * f;
}
template <class T>
T Abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
T Max(T a, T b) {
  return a > b ? a : b;
}
template <class T>
T Min(T a, T b) {
  return a < b ? a : b;
}
char s[N];
int n, cnt, tot, ans, a[N], b[N];
int get(int l, int r, int pos) {
  return min(Abs(pos - l), Abs(r - pos)) + r - l;
}
int check(int mid) {
  int last = 1, pos = 1;
  for (int i = 1; i <= tot; ++i) {
    while (pos <= cnt && get(b[last], b[pos], a[i]) <= mid) pos++;
    last = pos;
  }
  return cnt < pos;
}
int main() {
  n = read();
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) {
    if (s[i] == 'P')
      a[++tot] = i;
    else if (s[i] == '*')
      b[++cnt] = i;
  }
  int l = 0, r = 2 * n;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}
