#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, a[N], b[N], k1, k2, ans;
char s[N];
long long dis(long long x, long long l, long long r) {
  if (l >= x) return r - x;
  if (r <= x) return x - l;
  return min(x - l, r - x) + r - l;
}
bool solve(long long x) {
  long long l = 1, r = 1;
  for (long long i = 1; i <= k1; i++) {
    r = l;
    while (r <= k2 && dis(a[i], b[l], b[r]) <= x) r++;
    l = r;
  }
  return r == k2 + 1;
}
signed main() {
  scanf("%lld%s", &n, s + 1);
  for (long long i = 1; i <= n; i++) {
    if (s[i] == 'P')
      a[++k1] = i;
    else if (s[i] == '*')
      b[++k2] = i;
  }
  long long l = 0, r = n * 2;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (solve(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
