#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
int n;
string s;
bool solve(int len) {
  int p = 1, ult = 1;
  for (int i = 1; i <= n && p <= n; i++) {
    if (s[i] == 'P') {
      while (p <= n && s[p] != '*') p++;
      if (p > n) break;
      if (p < i) {
        if (i - len > p) return 0;
        int d = i - p;
        int p1 = p + len - d + 1;
        int p2 = i + (len - d) / 2 + 1;
        p = max(p1, p2);
      } else if (i + len >= p)
        p = i + len + 1;
    }
  }
  for (int i = p; i <= n; i++)
    if (s[i] == '*') return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;
  s = '.' + s;
  int ini = 1, fin = n * 2, med;
  while (ini < fin) {
    med = (ini + fin) / 2;
    if (solve(med))
      fin = med;
    else
      ini = med + 1;
  }
  cout << ini << "\n";
  return 0;
}
