#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int res = 0;
  int gNum = 0;
  int32_t n;
  scanf("%i", &n);
  ;
  std::string s;
  s.reserve(n + 1);
  std::cin >> s;
  s += 'S';
  char *prevStart = nullptr, *prevEnd = nullptr;
  char* start = nullptr;
  for (int32_t i = 0; i < n + 1; ++i) {
    if (s[i] == 'G') ++gNum;
    if (s[i] == 'G' && !start) {
      start = &s[i];
    }
    if (s[i] != 'G' && start) {
      int curRes = &s[i] - start;
      bool shouldIncremented = false;
      if (prevEnd && (start - prevEnd == 1)) {
        curRes += prevEnd - prevStart;
        shouldIncremented = true;
      }
      prevStart = start;
      prevEnd = &s[i];
      res = std::max(res, curRes);
      start = nullptr;
    }
  }
  if (gNum > res) ++res;
  std::cout << res;
  return 0;
}
