#include <bits/stdc++.h>
const int N = static_cast<const int>(1e5 + 10);
char s[N];
int n, ans, cnt;
std::vector<int> a, b;
int main() {
  scanf("%d%s", &n, s);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'G') cnt++;
    if (s[i] == 'S' && a.empty()) continue;
    if (i == 0 || s[i] != s[i - 1])
      (s[i] == 'G' ? a : b).push_back(1);
    else
      (s[i] == 'G' ? a : b).back() += 1;
  }
  for (auto i : a) ans = std::max(ans, i + 1);
  for (int i = 1; i < static_cast<int>(a.size()); i++)
    if (b[i - 1] == 1) ans = std::max(ans, a[i] + a[i - 1] + 1);
  ans = std::min(ans, cnt);
  printf("%d\n", ans);
  return 0;
}
