#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, count = 0, mx = 0;
  string s;
  cin >> n >> s;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'G')
      count++;
    else
      a.push_back(count), count = 0;
  }
  if (count > 0) a.push_back(count);
  int ind = -1;
  bool f = false;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] > 0) {
      if (ind == -1)
        ind = i;
      else {
        if (i - ind > 1) {
          f = true;
          break;
        }
      }
    }
  }
  for (int i = 0; i < a.size() - 1; i++) {
    mx = max(mx, a[i] + a[i + 1] + f);
  }
  cout << (a.size() == 1 ? *a.begin() : mx) << "\n";
}
