#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, Gcnt = 0, maxlen = 0, lastlen = 0, tmp;
  char trophies[100001];
  scanf("%d %s", &n, trophies);
  for (int i = 0; i < n; i++) {
    if (trophies[i] == 'G') Gcnt++;
  }
  if (Gcnt <= 1 || Gcnt == n) {
    printf("%d", Gcnt);
    return 0;
  }
  tmp = 0;
  for (int i = 0; i < n; i++) {
    if (trophies[i] == 'G') {
      tmp++;
    } else {
      if (lastlen != 0 && Gcnt > lastlen + tmp) {
        maxlen = max({maxlen, lastlen + tmp + 1, tmp});
      } else
        maxlen = max({maxlen, lastlen + tmp, tmp});
      if (Gcnt > tmp) maxlen = max({maxlen, tmp + 1});
      if (i + 1 < n && trophies[i + 1] == 'G') {
        lastlen = tmp;
      } else
        lastlen = 0;
      tmp = 0;
    }
  }
  if (lastlen != 0 && Gcnt > lastlen + tmp) {
    maxlen = max({maxlen, lastlen + tmp + 1, tmp});
  } else
    maxlen = max({maxlen, lastlen + tmp, tmp});
  if (Gcnt > tmp) maxlen = max({maxlen, tmp + 1});
  printf("%d", maxlen);
  return 0;
}
