#include <bits/stdc++.h>
using namespace std;
int n;
string s;
bool can(int tm) {
  int lf = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'P') {
      while (lf < n && s[lf] != '*') ++lf;
      if (i < lf) {
        if (lf > i + tm) continue;
        lf = i + tm + 1;
      } else {
        if (i - lf > tm) return false;
        lf = max(lf + tm - (i - lf) + 1, i + (tm - (i - lf)) / 2 + 1);
      }
    }
  }
  for (int i = lf; i < n; ++i)
    if (s[i] == '*') return false;
  return true;
}
int main() {
  cin >> n >> s;
  int l = -1;
  int h = 200100;
  while (h - l > 1) {
    int mid = (h + l) / 2;
    if (can(mid))
      h = mid;
    else
      l = mid;
  }
  printf("%d\n", h);
  return 0;
}
