#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  getchar();
  char a[100010];
  int b[100010];
  memset(b, 0, sizeof(b));
  for (int i = 0; i < n; i++) scanf("%c", &a[i]);
  int c = 0, ans = 0, ans1 = 0, ans2 = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 'G')
      ans++;
    else {
      b[c] = ans;
      ans = 0;
      if (b[c] != 0) c++;
      b[c] = 0;
      c++;
      ans1++;
    }
  }
  b[c] = ans;
  for (int i = 0; i <= c; i++) {
    if (b[i] != 0) ans2++;
  }
  int max1 = 0, lenth1 = 0;
  for (int j = 0; j <= c; j++) {
    if (b[j] != 0 && b[j + 2] != 0 && b[j + 1] == 0) {
      if (ans2 <= 2) {
        lenth1 = b[j] + b[j + 2];
      } else
        lenth1 = b[j] + b[j + 2] + 1;
    }
    if (b[j] != 0 && b[j + 2] == 0 && b[j + 1] == 0) {
      if (ans2 <= 1)
        lenth1 = b[j];
      else
        lenth1 = b[j] + 1;
    }
    max1 = max(max1, lenth1);
  }
  cout << max1 << endl;
  return 0;
}
