#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
long long n, S[100005], G[100005];
char str[100005];
bool check(long long x) {
  for (long long i = 1; i + x - 1 <= n; i++) {
    if (((S[i + x - 1] - S[i - 1]) == 0) ||
        (((S[i + x - 1] - S[i - 1]) == 1) &&
         ((G[i + x - 1] - G[i - 1]) != G[n]))) {
      return true;
    }
  }
  return false;
}
int main() {
  scanf("%lld", &n);
  scanf("%s", str + 1);
  for (long long i = 1; i <= n; i++) {
    G[i] = G[i - 1];
    S[i] = S[i - 1];
    if (str[i] == 'G') {
      G[i]++;
    } else {
      S[i]++;
    }
  }
  check(8);
  long long l = 0, r = n;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid)) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  printf("%lld\n", r);
}
