#include <bits/stdc++.h>
using namespace std;
const int MX = 10004;
int n, sol;
string inp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> inp;
  inp += 'S';
  int acc = 0, G = 0, s = -1;
  vector<pair<int, int> > sols;
  for (int i = 0; i <= n; i++) {
    if (inp[i] == 'G') {
      if (acc == 0) s = i;
      G++;
      acc++;
    } else if (acc > 0) {
      sols.push_back({s, i - 1});
      sol = max(sol, acc);
      acc = 0;
    }
  }
  if (G > sol) sol++;
  for (int i = 1; i < sols.size(); i++) {
    if (sols[i].first - sols[i - 1].second == 2) {
      int k = sols[i - 1].second - sols[i - 1].first + 1 + sols[i].second -
              sols[i].first + 1;
      sol = max(sol, k + (G > k));
    }
  }
  cout << sol;
  return 0;
}
