#include <bits/stdc++.h>
using namespace std;
template <typename X>
ostream& operator<<(ostream& x, const vector<X>& v) {
  for (long long i = 0; i < v.size(); ++i) x << v[i] << " ";
  return x;
}
template <typename X>
ostream& operator<<(ostream& x, const set<X>& v) {
  for (auto it : v) x << it << " ";
  return x;
}
template <typename X, typename Y>
ostream& operator<<(ostream& x, const pair<X, Y>& v) {
  x << v.ff << " " << v.ss;
  return x;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  for (auto it : v) os << it.first << "=>" << it.second << endl;
  return os;
}
struct pair_hash {
  inline std::size_t operator()(
      const std::pair<long long, long long>& v) const {
    return v.first * 31 + v.second;
  }
};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
vector<int> p;
bool vis[100005];
int n;
string s;
bool chk(int x) {
  int pre = 0;
  memset(vis, false, sizeof vis);
  for (int curr : p) {
    int lft = -1;
    int ii = curr - 1;
    int cnt = 0;
    while (ii >= pre) {
      if (!vis[ii] && s[ii] == '*') {
        lft = ii;
      }
      ii--;
    }
    cnt = curr - lft;
    if (cnt > x && lft != -1) {
      return false;
    }
    if (lft == -1) {
      for (int j = curr + 1; j <= min(curr + x, n - 1); j++) {
        vis[j] = true;
      }
      pre = curr;
      continue;
    }
    for (long long i = max(lft, 0); i < curr; i++) {
      vis[i] = true;
    }
    lft = curr - lft;
    int xx = max(max(x - 2 * lft, (x - lft) / 2), 0);
    for (int j = curr + 1; j <= min(curr + xx, n - 1); j++) {
      vis[j] = true;
    }
    pre = curr;
  }
  for (long long i = 0; i < n; i++) {
    if (s[i] == '*' && !vis[i]) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> n;
  cin >> s;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'P') {
      p.push_back(i);
    }
  }
  int lo = 1;
  int hi = 2 * n;
  if (chk(1)) {
    cout << 1 << endl;
    return 0;
  }
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (chk(mid)) {
      hi = mid - 1;
      if (!chk(hi)) {
        lo = mid;
        break;
      }
    } else {
      lo = mid + 1;
    }
  }
  cout << lo << endl;
}
