#include <bits/stdc++.h>
using namespace std;
int n;
char s[100005];
vector<int> v;
bool used[100005];
int main() {
  cin >> n;
  scanf("%s", s);
  s[n] = 'x';
  int now = 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] != s[i - 1]) {
      if (s[i - 1] == 'G') v.push_back(now);
      if (now == 1 && s[i - 1] == 'S') used[v.size()] = 1;
      now = 1;
    } else
      now++;
  }
  if (v.size() == 0)
    printf("0\n");
  else if (v.size() == 1)
    printf("%d\n", v[0]);
  else if (v.size() == 2) {
    if (used[1])
      printf("%d\n", v[0] + v[1]);
    else
      printf("%d\n", max(v[0], v[1]) + 1);
  } else {
    int ans = 0;
    for (int i = 0; i < v.size(); i++) ans = max(ans, v[i] + 1);
    for (int i = 1; i < v.size(); i++) {
      if (used[i]) ans = max(ans, v[i] + v[i - 1] + 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
