#include <bits/stdc++.h>
using namespace std;
const int maxn = 0x3f3f3f3f;
char str[200005];
int dp[200005];
int main() {
  int n;
  scanf("%d", &n);
  memset(dp, 0, sizeof(dp));
  scanf("%s", str);
  int tmp = 0, maxx = 0, k = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'G')
      tmp++;
    else
      tmp = 0;
    if (str[i + 1] == 'S' || i == n - 1) dp[i] = tmp;
  }
  tmp = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (str[i] == 'G' && dp[i + 1] != 0) {
      dp[i] = dp[i + 1];
    }
    maxx = max(maxx, dp[i]);
    if (str[i] == 'S' && str[i + 1] == 'G') tmp++;
    if (str[i] == 'S') k++;
  }
  if (str[0] == 'G') tmp++;
  if (tmp == 0)
    printf("0\n");
  else if (tmp == 1)
    printf("%d\n", maxx);
  else if (tmp == 2) {
    int flag = 0;
    for (int i = 1; i < n; i++) {
      if (dp[i] == 0 && dp[i - 1] > 0 && dp[i + 1] > 0) flag = 1;
    }
    if (flag)
      printf("%d\n", n - k);
    else
      printf("%d\n", maxx + 1);
  } else {
    maxx++;
    for (int i = 1; i < n; i++) {
      if (dp[i] == 0) {
        maxx = max(maxx, dp[i - 1] + dp[i + 1] + 1);
      }
    }
    printf("%d\n", maxx);
  }
  return 0;
}
