#include <bits/stdc++.h>
using namespace std;
const int N = 1000005, inf = 0x7fffffff;
template <class I>
inline void ckMax(I& p, I q) {
  p = (p > q ? p : q);
}
template <class I>
inline void ckMin(I& p, I q) {
  p = (p < q ? p : q);
}
template <class I>
inline I Min(I p, I q) {
  return p < q ? p : q;
}
template <class I>
inline I A(I x) {
  return x < 0 ? -x : x;
}
int n, pre[N], suf[N];
char s[N];
int main() {
  scanf("%d%s", &n, s + 1);
  register int i, cn = 0, tot = 0, ans = 0;
  for (i = 1; i <= n; ++i)
    if (s[i] == 'G')
      ++cn, ++tot;
    else
      pre[i] = cn, cn = 0;
  if (tot == n) return printf("%d\n", n), 0;
  for (i = n, cn = 0; i; --i)
    if (s[i] == 'G')
      ++cn;
    else
      suf[i] = cn, cn = 0;
  for (i = 1; i <= n; ++i)
    if (pre[i] + suf[i] < tot)
      ckMax(ans, pre[i] + suf[i] + 1);
    else
      ckMax(ans, tot);
  printf("%d", ans);
  return 0;
}
