#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char st[maxn];
int n;
int main() {
  cin >> n;
  scanf("%s", st);
  int len = strlen(st);
  int gold = 0, sliver = 0;
  for (int i = 0; i < len; ++i) {
    if (st[i] == 'G')
      gold++;
    else
      sliver++;
  }
  if (gold == 0)
    cout << 0 << endl;
  else if (sliver == 0)
    cout << gold << endl;
  else {
    int inter = 0, maxs = 0;
    bool flag = false;
    for (int i = 0; i < len; ++i) {
      if (st[i] == 'G') {
        inter++;
      } else {
        maxs = max(maxs, inter);
        inter = 0;
      }
    }
    maxs = max(maxs, inter);
    if (gold > maxs) maxs++;
    int maxs1 = 0;
    for (int i = 1; i < len - 1; ++i) {
      if (st[i] == 'S' && st[i - 1] == 'G' && st[i + 1] == 'G') {
        int a = i - 1, b = i + 1;
        while (a >= 0 && st[a] == 'G') a--;
        while (b < len && st[b] == 'G') b++;
        int cnt = b - a - 1;
        if (cnt > gold) cnt--;
        maxs1 = max(maxs1, cnt);
      }
    }
    int ans = max(maxs1, maxs);
    cout << ans << endl;
  }
  return 0;
}
