#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> A(n, 0), right(n, 0), left(n, 0);
  string s;
  cin >> s;
  long long maxi = 0;
  for (long long i = 0; i < n; i++)
    if (s[i] == 'G') A[i] = 1;
  long long seg = 0;
  long long c = 0;
  for (long long i = 0; i < n; i++) {
    if (A[i] == 1)
      c++;
    else {
      left[i] = c;
      if (c != 0) seg++;
      c = 0;
    }
    maxi = max(maxi, c);
  }
  if (c != 0) seg++;
  c = 0;
  for (long long i = n - 1; i >= 0; i--) {
    if (A[i] == 1)
      c++;
    else {
      right[i] = c;
      c = 0;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (A[i] == 0) {
      if (left[i] == 0 || right[i] == 0) {
        if (seg > 1) maxi = max(maxi, 1 + left[i] + right[i]);
      } else if (seg < 3)
        maxi = max(maxi, left[i] + right[i]);
      else
        maxi = max(maxi, left[i] + right[i] + 1);
    }
  }
  cout << maxi << endl;
  return 0;
}
