#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
char a[MAX_N];
int main() {
  int N;
  cin >> N;
  scanf("%s", a + 1);
  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    if (a[i] == 'S' && a[i] >= 2 && a[i - 1] == 'G') {
      cnt++;
    }
  }
  if (a[N] == 'G') cnt++;
  int len = 0, prelen = (cnt >= 2), ans = 0;
  for (int i = 1; i <= N; i++) {
    if (a[i] == 'G') {
      len++;
      ans = max(ans, len + prelen);
    }
    if (a[i] == 'S') {
      if (2 <= i && i <= N - 1 && a[i - 1] == 'G' && a[i + 1] == 'G') {
        if (cnt == 2) {
          prelen = len;
        } else if (cnt >= 3) {
          prelen = len + 1;
        }
      } else {
        prelen = (cnt >= 2);
      }
      len = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
